From d105436a13e7958c6146f4c365f9f173459cfad1 Mon Sep 17 00:00:00 2001 From: tkl Date: Sun, 14 Aug 2016 06:11:30 +0000 Subject: [PATCH] interface to grab wifi informations --- test_wireless.py | 12 ++++++++++++ wireless.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 test_wireless.py create mode 100644 wireless.py diff --git a/test_wireless.py b/test_wireless.py new file mode 100755 index 0000000..6c6c308 --- /dev/null +++ b/test_wireless.py @@ -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) diff --git a/wireless.py b/wireless.py new file mode 100644 index 0000000..5a9d458 --- /dev/null +++ b/wireless.py @@ -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