2016-03-21 08:33:52 +00:00
|
|
|
|
|
|
|
from re import match, sub
|
|
|
|
|
|
|
|
class wifi_fieldstrength:
|
|
|
|
def __init__(self, name = "wlan0"):
|
2016-04-07 04:50:41 +00:00
|
|
|
self._name = name
|
2016-03-21 08:33:52 +00:00
|
|
|
self.wf_name = "/proc/net/wireless"
|
|
|
|
|
2016-04-07 04:50:41 +00:00
|
|
|
def name(self):
|
|
|
|
return self._name
|
|
|
|
|
2016-03-21 08:33:52 +00:00
|
|
|
def read(self):
|
|
|
|
ret = False
|
|
|
|
f = open(self.wf_name, "r")
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
2016-04-07 04:50:41 +00:00
|
|
|
mstr = "^" + self._name
|
2016-03-21 08:33:52 +00:00
|
|
|
if match(mstr, line):
|
|
|
|
line = sub("\s+", " ", line)
|
|
|
|
tmp = line.split(" ")
|
|
|
|
tmp[3] = sub("\.", "", tmp[3])
|
|
|
|
ret = int(tmp[3])
|
|
|
|
return ret
|