interface to grab wifi informations

This commit is contained in:
tkl 2016-08-14 06:11:30 +00:00
parent c3e5cfe664
commit d105436a13
2 changed files with 45 additions and 0 deletions

12
test_wireless.py Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/python2
import wireless
import time
wf = wireless.wireless("wlan0")
while(True):
print "level: " + wf.level() + " dBm"
print "link: " + wf.link() + " dBm"
print "noise: " + wf.noise() + " dBm"
time.sleep(1)

33
wireless.py Normal file
View File

@ -0,0 +1,33 @@
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]
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