Skip to content

Instantly share code, notes, and snippets.

@RaffaeleSgarro
Created March 2, 2013 12:34
Show Gist options
  • Save RaffaeleSgarro/5070818 to your computer and use it in GitHub Desktop.
Save RaffaeleSgarro/5070818 to your computer and use it in GitHub Desktop.
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