使用scapy嗅探特定端口上的通信量

2024-04-23 19:28:40 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我有客户机和服务器代码。

服务器代码如下所示:

import socket
import sys

HOST = ''   
PORT = 5555

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

#Bind socket to local host and port
try:
    s.bind((HOST, PORT))
except socket.error as msg:
    print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()

print 'Socket bind complete'

#Start listening on socket
s.listen(10)
print 'Socket now listening'

#now keep talking with the client
while 1:
    conn, addr = s.accept()
    print 'Connected with ' + addr[0] + ':' + str(addr[1])
    data = conn.recv(10000)
    print data
s.close()

现在我想做的是对这个套接字(端口5555)上的这些传入数据包进行一些分析。基本上我想要提取头标志。我试着用scapy函数sniff()来完成这个任务,这里有Fetch source address and port number of packet - Scapy script

只有我能嗅到端口上的数据包。。没有其他流量。

我该怎么做?


Tags: and代码import服务器hostbindportsys