def __init__(self, interface): threading.Thread.__init__(self) self.interface = interface self.sem = threading.Semaphore() self.running = True self.eth = dumbnet.eth(interface) self.out = None
def update_devices(self): self.devices = {} devs = pcap.findalldevs() for (name, descr, addr, flags) in devs: try: test = dumbnet.eth(name) mac = test.get() self.devices[name] = { 'mac': mac, 'ip4': [], 'ip6': [], 'descr': descr, 'flags': flags } except: pass else: if len(addr) > 1: for (ip, mask, net, gw) in addr: try: dumbnet.ip_aton(ip) addr_dict = {} addr_dict['ip'] = ip addr_dict['mask'] = mask addr_dict['net'] = net addr_dict['gw'] = gw self.devices[name]['ip4'].append(addr_dict) except: pass try: dumbnet.ip6_aton(ip) addr_dict = {} addr_dict['ip'] = ip if PLATFORM == "Windows" and mask is None: addr_dict['mask'] = "ffff:ffff:ffff:ffff::" else: addr_dict['mask'] = mask addr_dict['net'] = net addr_dict['gw'] = gw if ip.startswith("fe80:"): addr_dict['linklocal'] = True else: addr_dict['linklocal'] = False self.devices[name]['ip6'].append(addr_dict) except: pass else: #???? pass
def run(self): self.d = dumbnet.eth(self.parent.interface) p = pcap.pcapObject() p.open_live(self.parent.interface, 1600, 1, 100) if not self.parent.platform == "Darwin": p.setnonblock(1) p.setfilter(self.filter, 0, 0) while self.running: try: p.dispatch(1, self.dispatch) except Exception, e: print e if DEBUG: print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 time.sleep(0.001)