Created
March 2, 2013 12:34
-
-
Save RaffaeleSgarro/5070818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import commands, re | |
import pprint | |
class Engine: | |
def __init__(self): | |
self.data = dict() | |
def updateSourceEvent(self): | |
self.updateData() | |
self.setData("wireless", "strength", self.strength) | |
self.setData("wireless", "ip", self.ip) | |
self.setData("wireless", "essid", self.essid) | |
self.setData("wireless", "gateway", self.gateway) | |
def updateData(self): | |
interface = commands.getoutput("cat /proc/net/wireless | tail -n1 | awk '{print$1}' | cut -d: -f1") | |
blob = commands.getoutput("/sbin/iwconfig " + interface) | |
match = re.search("Link Quality=(\d+)/(\d+)", blob) | |
self.strength = 100 * int(match.group(1)) / int(match.group(2)) | |
match = re.search("ESSID:\"(.+)\"", blob) | |
self.essid = match.group(1) | |
self.ip = commands.getoutput("/sbin/ip addr show %s | grep inet | head -n1 | awk '{print$2}' | cut -d/ -f1" % interface) | |
self.gateway = commands.getoutput("netstat -rn | grep %s | tail -n1 | awk '{print$2}'" % interface) | |
def setData(self, org, key, value): | |
self.data[org + "." + key] = value | |
engine = Engine() | |
engine.updateSourceEvent() | |
pprint.pprint(engine.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment