def get_devices (): def ip (addr): if addr is None: return None return IPAddr(addr, networkOrder=True) def link (addr): if addr is None: return None if len(addr) != 6: return None return EthAddr(addr) devs = pcapc.findalldevs() out = {} for d in devs: addrs = {} n = {'desc':d[1],'addrs':addrs} out[d[0]] = n for a in d[2]: if a[0] == 'AF_INET': na = {} addrs[a[0]] = na na['addr'] = ip(a[1]) na['netmask'] = ip(a[2]) na['broadaddr'] = ip(a[3]) na['dstaddr'] = ip(a[4]) elif a[0] == 'AF_LINK': na = {} addrs[a[0]] = na na['addr'] = link(a[1]) na['netmask'] = link(a[2]) na['broadaddr'] = link(a[3]) na['dstaddr'] = link(a[4]) elif a[0] == 'AF_PACKET': addrs[a[0]] = {'addr':link(a[1])} elif a[0] == 'ethernet': addrs[a[0]] = {'addr':link(a[1])} return out
def get_devices(): def ip(addr): if addr is None: return None return IPAddr(addr, networkOrder=True) def ip6(addr): if addr is None: return None return IPAddr6.from_raw(addr) def link(addr): if addr is None: return None if len(addr) != 6: return None return EthAddr(addr) devs = pcapc.findalldevs() out = {} for d in devs: addrs = {} n = {"desc": d[1], "addrs": addrs} out[d[0]] = n for a in d[2]: if a[0] == "AF_INET": na = {} addrs[a[0]] = na na["addr"] = ip(a[1]) na["netmask"] = ip(a[2]) na["broadaddr"] = ip(a[3]) na["dstaddr"] = ip(a[4]) elif a[0] == "AF_INET6": na = {} addrs[a[0]] = na na["addr"] = ip6(a[1]) na["netmask"] = ip6(a[2]) na["broadaddr"] = ip6(a[3]) na["dstaddr"] = ip6(a[4]) elif a[0] == "AF_LINK": na = {} addrs[a[0]] = na na["addr"] = link(a[1]) na["netmask"] = link(a[2]) na["broadaddr"] = link(a[3]) na["dstaddr"] = link(a[4]) elif a[0] == "AF_PACKET": addrs[a[0]] = {"addr": link(a[1])} elif a[0] == "ethernet": addrs[a[0]] = {"addr": link(a[1])} return out
def get_device_names(): return [d[0] for d in pcapc.findalldevs()]
def get_device_names (): return [d[0] for d in pcapc.findalldevs()]