本文整理汇总了Python中pcapy.PcapError方法的典型用法代码示例。如果您正苦于以下问题:Python pcapy.PcapError方法的具体用法?Python pcapy.PcapError怎么用?Python pcapy.PcapError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pcapy
的用法示例。
在下文中一共展示了pcapy.PcapError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import PcapError [as 别名]
def next(self):
try:
c = self.pcap.next()
except pcap.PcapError:
return None
else:
h,p = c
s,us = h.getts()
return (s+0.000001*us), p
示例2: packetHandler
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import PcapError [as 别名]
def packetHandler(self, hdr, data):
"""Handles an incoming pcap packet. This method only knows how
to recognize TCP/IP connections.
Be sure that only TCP packets are passed onto this handler (or
fix the code to ignore the others).
Setting r"ip proto \tcp" as part of the pcap filter expression
suffices, and there shouldn't be any problem combining that with
other expressions.
"""
# Use the ImpactDecoder to turn the rawpacket into a hierarchy
# of ImpactPacket instances.
p = self.decoder.decode(data)
ip = p.child()
tcp = ip.child()
# Build a distinctive key for this pair of peers.
src = (ip.get_ip_src(), tcp.get_th_sport() )
dst = (ip.get_ip_dst(), tcp.get_th_dport() )
con = Connection(src,dst)
# If there isn't an entry associated yetwith this connection,
# open a new pcapdumper and create an association.
if ('%s%s' % (con.p1, con.p2)) not in self.connections:
fn = con.getFilename()
print("Found a new connection, storing into:", fn)
try:
dumper = self.pcap.dump_open(fn)
except pcapy.PcapError:
print("Can't write packet to:", fn)
return
self.connections['%s%s' % (con.p1, con.p2)] = dumper
# Write the packet to the corresponding file.
self.connections['%s%s' % (con.p1, con.p2)].dump(hdr, data)
示例3: poll
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import PcapError [as 别名]
def poll(self,event = None):
self.tk.after(POLL_PERIOD, self.poll)
received = 0
while 1:
try:
hdr, data = self.p.next()
except PcapError, e:
break
self.newPacket(hdr.getcaplen(), data, hdr.getts()[0])
received = 1
示例4: packetHandler
# 需要导入模块: import pcapy [as 别名]
# 或者: from pcapy import PcapError [as 别名]
def packetHandler(self, hdr, data):
"""Handles an incoming pcap packet. This method only knows how
to recognize TCP/IP connections.
Be sure that only TCP packets are passed onto this handler (or
fix the code to ignore the others).
Setting r"ip proto \tcp" as part of the pcap filter expression
suffices, and there shouldn't be any problem combining that with
other expressions.
"""
# Use the ImpactDecoder to turn the rawpacket into a hierarchy
# of ImpactPacket instances.
p = self.decoder.decode(data)
ip = p.child()
tcp = ip.child()
# Build a distinctive key for this pair of peers.
src = (ip.get_ip_src(), tcp.get_th_sport() )
dst = (ip.get_ip_dst(), tcp.get_th_dport() )
con = Connection(src,dst)
# If there isn't an entry associated yetwith this connection,
# open a new pcapdumper and create an association.
if not self.connections.has_key(con):
fn = con.getFilename()
print "Found a new connection, storing into:", fn
try:
dumper = self.pcap.dump_open(fn)
except pcapy.PcapError, e:
print "Can't write packet to:", fn
return
self.connections[con] = dumper
# Write the packet to the corresponding file.