Пример #1
0
 def geterr(self):
     return cpcap.geterr(self._p)
Пример #2
0
 def getaddr(interface):
     ip, mac = cpcap.getaddr(interface)
     ip = struct.pack("i", ip)
     return ip_from_bin(ip), mac_from_bin(mac)
Пример #3
0
 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)
Пример #4
0
 def read(self):
     packet, stamp = cpcap.read(self._p)
     t = datetime.fromtimestamp(stamp["sec"] + stamp["usec"] / 1000000.0)
     return (Packet(packet), t)
Пример #5
0
 def send(self, packet):
     cpcap.send(self._p, str(packet))
Пример #6
0
 def __del__(self):
     if hasattr(self, "_fp"):
         cpcap.freecode(self._fp)
     cpcap.close(self._p)
     del self._p
Пример #7
0
 def __init__(self, device, snaplen=65535, promisc=False, to_ms=0):
     self._p = cpcap.open(device, snaplen, promisc, to_ms)
     self.device = device