python-scapy:如何将端口号转换为服务名称?
Scapy 中的 TCP 层包含源端口:
>>> a[TCP].sport
80
是否有一种简单的方法将端口号转换为服务名称? 我见过 Scapy 有 TCP_SERVICES
和 UDP_SERVICES
来转换端口号,但
print TCP_SERVICES[80] # fails
print TCP_SERVICES['80'] # fails
print TCP_SERVICES.__getitem__(80) # fails
print TCP_SERVICES['www'] # works, but it's not what i need
80
有人知道如何将端口映射到服务?
先感谢您
A TCP layer in Scapy contains source port:
>>> a[TCP].sport
80
Is there a simple way to convert port number to service name? I've seen Scapy has TCP_SERVICES
and UDP_SERVICES
to translate port number, but
print TCP_SERVICES[80] # fails
print TCP_SERVICES['80'] # fails
print TCP_SERVICES.__getitem__(80) # fails
print TCP_SERVICES['www'] # works, but it's not what i need
80
Someone know how can I map ports to services?
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Python 的 socket 模块将执行此操作:
Python's socket module will do that:
如果这是您需要经常执行的操作,您可以创建
TCP_SERVICES
的反向映射:If this is something you need to do frequently, you can create a reverse mapping of
TCP_SERVICES
:这可能对您有用(根据值过滤字典):
This may work for you (filtering the dictionary based on the value):
如果您使用的是 unix 或 linux,则有一个文件 /etc/services 包含此映射。
If you are using unix or linux there is a file /etc/services which contains this mapping.
我找到了一个很好的解决方案来填充另一个字典 self.MYTCP_SERVICES
I've found a good solution filling another dict self.MYTCP_SERVICES