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