[英]sniff traffic on a particular port using scapy
Ok so I have client and a server code. 好的,我有客户端和服务器代码。
The server code looks like this : 服务器代码如下所示:
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()
Now what I wanna be able to do is to conduct some analysis on these incoming packets on that socket (port 5555). 现在我想做的是对该套接字上的这些传入数据包进行一些分析(端口5555)。 Basically I want extract header flags.
基本上我想要提取头标志。 I was trying to do this using scapy function sniff() as found here Fetch source address and port number of packet - Scapy script
我试图使用scapy函数sniff()来执行此操作,如此处获取数据包的源地址和端口号 - Scapy脚本
only i wanna be able to just sniff packets coming in on that port .. not any other traffic. 只有我想能够只是嗅到进入该端口的数据包..而不是任何其他流量。
How do I go about doing this ? 我该怎么做呢?
The following will capture all packets with destination port number equal to 5555 on all available interfaces. 以下内容将捕获所有可用接口上目标端口号等于5555的所有数据包。
sniff(filter = 'dst port 5555')
You can of course specify the interface that you wish to sniff on by specifying the iface parameter. 您当然可以通过指定iface参数来指定要嗅探的界面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.