以前一直不知道普通的路由器的弹出框是怎么搞的,最近才无意中知道是用basic认证的.正好可以使用下面的代码进行认证
代码如下 | 复制代码 |
import urllib2, base64 def listen_server(url,user,password): request = urllib2.Request(url) base64string = base64.encodestring('%s:%s' % (user,password))[:-1] request.add_header("Authorization", "Basic %s" % base64string) try: htmlFile = urllib2.urlopen(request) htmlData = htmlFile.read() if '/var/lib/mysql/mysql.sock' in htmlData: htmlFile.close() return(-1) else: htmlFile.close() except: return(-1) |
时间: 2024-11-27 17:16:40