Python3:Scapy属性IP需要ip4地址作为参数,但我只有url

问题描述 投票:0回答:2

我正在使用scapy来对使用Python中的HTMLParser lib的网络爬虫进行协议。我需要将网页的网址转换为IP4,或者将其转换为接受网址输入的scapy.IP方法。

reference code

这里是我感兴趣的答案的代码:

from scapy.all import wrpcap, Ether, IP, UDP
packet = Ether() / IP(dst="1.2.3.4") / UDP(dport=123)
wrpcap('foo.pcap', [packet])

现在似乎很清楚,dstdport只是一个例子而已。如何用URL的真实数据(ip4和dport)代替这些假人?具有IP网址功能或有快速的转换方式,例如http.www.google.com变成了IP地址?以及如何获得正确的dport?

python-3.x url ip scapy converters
2个回答

0
投票
您可以ping它:

$ ping stackoverflow.com PING stackoverflow.com (151.101.193.69): 56 data bytes 64 bytes from 151.101.193.69: icmp_seq=0 ttl=46 time=374.685 ms 64 bytes from 151.101.193.69: icmp_seq=1 ttl=46 time=397.401 ms 64 bytes from 151.101.193.69: icmp_seq=2 ttl=46 time=684.908 ms 64 bytes from 151.101.193.69: icmp_seq=3 ttl=46 time=301.389 ms 那么您将知道stackoverflow.com的IP为151.101.193.69

© www.soinside.com 2019 - 2024. All rights reserved.