From e607030428b4fd48d860e0c0a25cbe18f83437e1 Mon Sep 17 00:00:00 2001 From: Tobias Mueller Date: Wed, 12 Jan 2011 13:50:34 +0100 Subject: [PATCH] setup and tear down monitor in separate functions and change DBus API for Start() --- pwnitter.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pwnitter.py b/pwnitter.py index 4d661fd..a0860be 100755 --- a/pwnitter.py +++ b/pwnitter.py @@ -29,15 +29,18 @@ class Pwnitter(dbus.service.Object): self.status = status self.is_running = False - @dbus.service.method(NAME, - in_signature='', out_signature='') - def Start(self, device='mon0'): - # FIXME: Prevent double Start() + def setup_monitor(device='mon0'): # FIXME: Replace hardcoded interface cmd = '/usr/sbin/iw wlan0 interface add mon0 type monitor'.split() subprocess.call(cmd) cmd = '/sbin/ifconfig mon0 up'.split() subprocess.call(cmd) + + @dbus.service.method(NAME, + in_signature='', out_signature='') + def Start(self): + # FIXME: Prevent double Start() + self.setup_monitor(self.device): self.is_running = True try: self.cap = pcap.pcap(device) @@ -68,16 +71,20 @@ class Pwnitter(dbus.service.Object): def GetMessage(self): return self.status + + def tear_down_monitor(device='mon0'): + cmd = '/sbin/ifconfig mon0 down'.split() + subprocess.call(cmd) + cmd = '/usr/sbin/iw dev mon0 del'.split() + subprocess.call(cmd) + @dbus.service.method(NAME, in_signature='', out_signature='') def Stop(self): self.is_running = False print "Receive Stop" gobject.source_remove(self.source_id) - cmd = '/sbin/ifconfig mon0 down'.split() - subprocess.call(cmd) - cmd = '/usr/sbin/iw dev mon0 del'.split() - subprocess.call(cmd) + self.tear_down_monitor(self.device) loop.quit() -- 1.7.9.5