本文整理匯總了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)