本文整理汇总了Python中pcap.pcapObject方法的典型用法代码示例。如果您正苦于以下问题:Python pcap.pcapObject方法的具体用法?Python pcap.pcapObject怎么用?Python pcap.pcapObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pcap
的用法示例。
在下文中一共展示了pcap.pcapObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcapObject [as 别名]
def main():
# setup commandline arguments
parser = argparse.ArgumentParser(description='Packet Sniffer')
parser.add_argument('--iface', action="store", dest="iface", default='eth0')
parser.add_argument('--port', action="store", dest="port", default=80, type=int)
# parse arguments
given_args = parser.parse_args()
iface, port = given_args.iface, given_args.port
# start sniffing
pc = pcap.pcapObject()
pc.open_live(iface, 1600, 0, 100)
pc.setfilter('dst port %d' %port, 0, 0)
print ('Press CTRL+C to end capture')
try:
while True:
pc.dispatch(1, print_packet)
except KeyboardInterrupt:
print ('Packet statistics: %d packets received, %d packets dropped, %d packets dropped by the interface' % pc.stats())
开发者ID:PacktPublishing,项目名称:Python-Network-Programming-Cookbook-Second-Edition,代码行数:21,代码来源:8_1_packet_sniffer.py
示例2: __init__
# 需要导入模块: import pcap [as 别名]
# 或者: from pcap import pcapObject [as 别名]
def __init__(self, *args, **kargs):
self.pcap = pcap.pcapObject()
self.pcap.open_live(*args, **kargs)