本文整理汇总了Python中pcap.pcap方法的典型用法代码示例。如果您正苦于以下问题:Python pcap.pcap方法的具体用法?Python pcap.pcap怎么用?Python pcap.pcap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pcap
的用法示例。
在下文中一共展示了pcap.pcap方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setfilter
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def setfilter(self, filter):
self.pcap.setfilter(filter, 0, 0)
示例2: next
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def next(self):
c = self.pcap.next()
if c is None:
return
l,pkt,ts = c
return ts,pkt
示例3: __init__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def __init__(self, system, config=None):
self.system = system
self.config = config
if "lo" in self.config.ifname:
eth_dst = b""
eth_src = b""
eth_type = bytearray.fromhex("1e000000")
else:
# XXX
eth_dst = bytearray.fromhex(
self.config.eth_dst.replace(":", ""))
eth_src = bytearray.fromhex(
self.config.eth_src.replace(":", ""))
eth_type = bytearray.fromhex("86dd")
self.eth_hdr = eth_dst + eth_src + eth_type
self.pcap = pcap.pcap(self.config.ifname, immediate=True)
self.pcap.setdirection(pcap.PCAP_D_OUT)
示例4: __init__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def __init__(self, *args, **kargs):
self.pcap = pcap.open_live(*args, **kargs)
示例5: __getattr__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def __getattr__(self, attr):
return getattr(self.pcap, attr)
示例6: decode_pcap
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def decode_pcap(self, fspec):
with open(fspec, "rb") as f:
for ts, frame in dpkt.pcap.Reader(f):
self.handle_frame(ts, frame)
print()
print("Frames: {}".format(self.frame_count))
print("Packets: {}".format(self.packet_count))
if self.packet_count:
print("Unknown packets: {} ({:.0f}%)".format(
self.unknown_count, 100.0*self.unknown_count/self.packet_count))
示例7: capture
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def capture(self, interface):
pc = pcap.pcap(name=interface)
# pc.setfilter('')
print('listening on %s: %s' % (pc.name, pc.filter))
pc.loop(0, self.handle_frame)
示例8: main
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def main():
fspec = sys.argv[1]
app = DumpApp()
if os.path.exists(fspec):
app.decode_pcap(fspec)
else:
if pcap is None:
sys.exit("Live packet capturing requires pypcap. Install with 'pip install pypcap'.")
app.capture(fspec)
示例9: get_macs
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def get_macs(fname):
pc = pcap.pcap(fname)
for ts, pkt in pc:
pkt = dpkt.ethernet.Ethernet(pkt)
yield ts, struct.unpack("!Q", "\0\0"+pkt.src)[0], struct.unpack("!Q", "\0\0"+pkt.dst)[0]
示例10: __init__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def __init__(self, device, snaplen, promisc, to_ms):
try:
self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1, timeout_ms=to_ms)
except TypeError:
# Older pypcap versions do not support the timeout_ms argument
self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1)
示例11: next
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def next(self):
c = self.pcap.next()
if c is None:
return
ts, pkt = c
return ts, str(pkt)
示例12: __del__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def __del__(self):
fd = self.pcap.fileno()
os.close(fd)
示例13: __init__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcap [as 别名]
def __init__(self, device, snaplen, promisc, to_ms):
# Normal pypcap module has no timeout parameter,
# only the specially patched "scapy" variant has.
if "scapy" in pcap.__version__.lower():
self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1, timeout_ms=to_ms)
else:
self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1)