7 theurl
= 'http://192.168.1.1:8088/userRpm/StatusRpm.htm?'
12 passman
= urllib2
.HTTPPasswordMgrWithDefaultRealm()
13 # this creates a password manager
14 passman
.add_password(None, theurl
, username
, password
)
15 # because we have put None at the start it will always use this
16 # username/password combination for urls for which `theurl` is a super-url
18 authhandler
= urllib2
.HTTPBasicAuthHandler(passman
)
19 # create the AuthHandler
21 opener
= urllib2
.build_opener(authhandler
)
23 urllib2
.install_opener(opener
)
24 # All calls to urllib2.urlopen will now use our handler Make sure not to
25 # include the protocol in with the URL, or HTTPPasswordMgrWithDefaultRealm will
26 # be very confused. You must (of course) use it when fetching the page though.
29 pagehandle
= urllib2
.urlopen(theurl
)
30 except urllib2
.URLError
:
31 return 'No route to host'
32 # authentication is now handled automatically for us
34 thepage
= pagehandle
.read()
37 pa
= re
.compile(r
'(var wanPara = new Array\(.*0, "[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]", ")(\d+.\d+.\d+.\d+)', re
.DOTALL
)
39 m
= pa
.search(thepage
)
43 if __name__
=='__main__':