我正在尝试使用 Scapy 在 Python 中编写一个脚本,该脚本发出 DNS 请求并接收 DNS 响应。 这是我写的:
packet = IP(dst="1.1.1.1")/ICMP()
res = sr1(packet)
if res:
print "---------------------------------------"
print "Host is Up, trying DNS Query"
print "---------------------------------------"
packet = IP(dst="1.1.1.1") / UDP() / DNS(rd=1, qd=DNSQR(qname="www.google.com"))
sr1(packet)
else:
print "Destination Unreachable!"
当我运行这段代码时,ping (ICMP) 工作并收到响应,但当它发送 DNS 查询时,它会显示:
Begin emission:
Finished sending 1 packets.
.....................................................................
它一直打印点,直到我停止它并打印:“收到 83 个数据包,得到 0 个答案,剩余 1 个数据包”。
你知道如何解决这个问题吗? 预先感谢您的回答。
最佳答案
编辑:查看文档:https://scapy.readthedocs.io/en/latest/usage.html#dns-requests
使用最新的 scapy 版本,我无法复制:/ 您发布的代码有效
一些可能对您有帮助的事情:
- 使用最新的开发版本:发布速度非常慢。在这里下载https://github.com/secdev/scapy/archive/master.zip并通过 python setup.py install 安装(Unix 上的 sudo)
- 尝试手动指定接口(interface)(在
sr1
中使用iface=...
)。完整列表可通过get_if_list()
获得
- 检查您的防火墙。它可能会阻塞数据包
关于python - Scapy DNS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53728027/