今のところ、弱い 0、やや弱い 1 の区別が確認出来ています。
# uroadhome.py 2012.3.17 # -*- coding: utf-8 -*- import re import base64 import urllib2 import urlparse import time import datetime from optparse import OptionParser def get_status(url): o = urlparse.urlparse(url) if o.username and o.password: user_passwd = o.username+":"+o.password url = url.replace(user_passwd+"@", "", 1) req = urllib2.Request(url) req.add_header("Authorization", "Basic " + base64.encodestring(user_passwd)) else: req = urllib2.Request(url) try: #response = urllib2.urlopen(req, timeout=2) response = urllib2.urlopen(req) # ver2.5 except urllib2.HTTPError, err: print err return None except urllib2.URLError, err: print err return None except socket.timeout: return None else: data = response.read() data = unicode(data.replace("\n", ""), 'utf-8') m = re.search(r"Info\((.+)\)", data) if m: d = m.group(1) s = d.split(",") return s[5].strip().strip("\"") return None if __name__ == "__main__": parser = OptionParser() parser.add_option("-p", "--password", dest="password") (options, args) = parser.parse_args() # Uroad-Home url = "http://admin:%s@192.168.100.254/admin/RS_getWiMAXInfo.asp" % options.password while 1: try: dt = datetime.datetime.now() print dt.strftime('%Y-%m-%d %H:%M:%S'), status = get_status(url) if status: print u"電波強度[%s]" % status else: print u"---" time.sleep(3) except KeyboardInterrupt: break---
0 件のコメント:
コメントを投稿