通过UDP和python进行基本的DNS查询

时间:2015-10-26 01:23:51

标签: python dns udp

在这个问题中:https://serverfault.com/questions/173187/what-does-a-dns-request-look-like有一个示例UDP数据包,可用于向DNS服务器查询www.google.com的地址。

我写了一个基本的Python代码段:

from socket import *
s = socket(AF_INET, SOCK_DGRAM)

raw = "24 1a 01 00 00 01 00 00 00 00 00 00 03 77  77 77 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 00 01  00 01"
hex = raw.split()

ints = [int(i, 16) for i in hex]
bytes = [chr(i) for i in ints]

packet = "".join(bytes)
s.sendto(packet, ("8.8.8.8", 53))

s.recvfrom(1024)

但没有任何反应。我没有回应。我究竟做错了什么?我错过了什么吗?我不应该在同一个端口上收到UDP数据包并回答我的查询吗?

0 个答案:

没有答案