電波強度としては、強い、普通、弱い、少し弱い、非常に弱い、圏外が区別できるようだ。
# -*- coding: utf-8 -*- # uroad7000.py 2011.10.27 import base64 import urllib2 import urlparse import time import datetime from BeautifulSoup import BeautifulSoup 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) 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() soup = BeautifulSoup(data) for td in soup('td', id="WM_ConnectionStatus"): s = td.contents[0] if ord(s[0]) == 0xfeff: s = s[2:] status = s.strip(' ') return status return None if __name__ == "__main__": # Uroad-7000SS url = "http://admin:admin@192.168.100.254/admin/wimax_status.asp" while 1: try: print datetime.datetime.now(), status = get_status(url) if status: print u"電波強度[%s]" % status else: print u"---" time.sleep(0.5) except KeyboardInterrupt: break
---
0 件のコメント:
コメントを投稿