def geterr(self): return cpcap.geterr(self._p)
def getaddr(interface): ip, mac = cpcap.getaddr(interface) ip = struct.pack("i", ip) return ip_from_bin(ip), mac_from_bin(mac)
def filter(self, code, optimize=True, netmask=0): if hasattr(self, "_fp"): cpcap.freecode(self._fp) if code: self._fp = cpcap.filter(self._p, code, optimize, netmask)
def read(self): packet, stamp = cpcap.read(self._p) t = datetime.fromtimestamp(stamp["sec"] + stamp["usec"] / 1000000.0) return (Packet(packet), t)
def send(self, packet): cpcap.send(self._p, str(packet))
def __del__(self): if hasattr(self, "_fp"): cpcap.freecode(self._fp) cpcap.close(self._p) del self._p
def __init__(self, device, snaplen=65535, promisc=False, to_ms=0): self._p = cpcap.open(device, snaplen, promisc, to_ms) self.device = device