interface to grab wifi informations
This commit is contained in:
parent
c3e5cfe664
commit
d105436a13
12
test_wireless.py
Executable file
12
test_wireless.py
Executable 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
33
wireless.py
Normal 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
|
Loading…
Reference in New Issue
Block a user