commclient/wireless.py

36 lines
720 B
Python
Raw Normal View History

2016-08-14 06:11:30 +00:00
import re
class wireless:
def __init__(self, device = "wlan0"):
self.device = device
self.__link = ""
self.__level = ""
self.__noise = ""
def __parse(self):
f = open("/proc/net/wireless", "r")
for line in f:
line = line.strip()
if re.match("^" + self.device + ".*$", line):
line = re.sub("\s+", " ", line)
lst = line.split(" ")
self.__link = lst[2]
self.__level = lst[3]
2016-08-14 09:21:43 +00:00
if re.match(".*\.$", self.__level):
self.__level = re.sub("\.", "", self.__level)
2016-08-14 06:11:30 +00:00
self.__noise = lst[4]
break
f.close()
def level(self):
self.__parse()
return self.__level
def link(self):
self.__parse()
return self.__link
def noise(self):
self.__parse()
return self.__noise