3
我在python編程,我有一個問題,事實上,當我發現我的腳本結束了幾秒鐘後,他檢測到一個IP6數據包。顯然,我必須過濾數據包,並採取只有IP4數據包,以避免這個問題,我想知道如何可以使用它與圖書館dpkt如果可能的,因爲我開始。 我試過的東西,但我是一個初學者,它不工作,你能在這方面看到:異常IP6沒有任何屬性
#Select Ipv4 packets because of problem with the .p in Ipv6
if ip.p == dpkt.ip6:
return`
遇到的錯誤說:「AttributeError的:‘IP6’對象有沒有屬性‘P’」 。這是回溯:
這是我的代碼,如果你想看看:) 感謝您的時間:)
import pcapy
import dpkt
from threading import Thread
import re
import binascii
liste=[]
listip=[]
piece_request_handshake = re.compile('13426974546f7272656e742070726f746f636f6c(?P<reserved>\w{8})(?P<info_hash>\w{20})(?P<peer_id>\w{20})')
piece_request_tcpclose = re.compile('(?P<start>\w{12})5011')
class PieceRequestSniffer(Thread):
def __init__(self, dev='eth0'):
Thread.__init__(self)
self.expr = 'udp or tcp'
self.maxlen = 65535 # max size of packet to capture
self.promiscuous = 1 # promiscuous mode?
self.read_timeout = 100 # in milliseconds
self.max_pkts = -1 # number of packets to capture; -1 => no limit
self.active = True
self.p = pcapy.open_live(dev, self.maxlen, self.promiscuous, self.read_timeout)
self.p.setfilter(self.expr)
@staticmethod
def cb(hdr, data):
eth = dpkt.ethernet.Ethernet(str(data))
ip = eth.data
#Select only TCP protocols
if ip.p == dpkt.ip.IP_PROTO_TCP:
tcp = ip.data
#Select Ipv4 packets because of problem with the .p in Ipv6
if ip.p == dpkt.ip6:
return
else:
try:
#Return hexadecimal representation
hex_data = binascii.hexlify(tcp.data)
except:
return
handshake = piece_request_handshake.findall(hex_data)
if handshake:
print "-----------handsheck filtered-------------"
liste.append(handshake)
print "\n"
#for element in zip(liste,"123456789abcdefghijklmnopqrstuvwxyz"):
# print(element)
def stop(self):
self.active = False
def run(self):
while self.active:
self.p.dispatch(0, PieceRequestSniffer.cb)
sniffer = PieceRequestSniffer()
sniffer.start()
還PL緩解後完整的通話回溯 – cmidi
通緝令,但我無法在我的10點聲譽什麼是很愚蠢的... – Bouh10
似乎很奇怪。在IP6的情況下你是否嘗試使用IP6.nxt字段而不是IP6.p字段來進行測試。你可以檢查從以太網頭的IP版本,使交換機 – cmidi