【问题标题】:Unable to change DNS resolver to localhost无法将 DNS 解析器更改为 localhost
【发布时间】:2016-03-24 09:05:01
【问题描述】:

我将 Windows 机器的 DNS 服务器配置为127.0.0.1,并在本地主机上创建了一个基本的python server

from socket import *
serverPort = 53
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('127.0.0.1', serverPort))
print "The server is ready to receive on port: {}".format(serverPort)
while 1:
    try:
        message, clientAddress = serverSocket.recvfrom(512)
    except:
        continue
    print clientAddress, message
    modifiedMessage = "127.0.0.1"
    serverSocket.sendto(modifiedMessage, clientAddress)

PS :我知道 DNS 是一个二进制协议,发送 ASCII 文本不会有任何好处,但我不是想制作解析器,我是试图透明地了解前者的工作原理。

当我启动服务器时,我很高兴看到以下输出:

(('127.0.0.1', 53945), '.\x9c\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 53945), '.\x9c\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 53945), '.\x9c\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 61362), '\xefc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 50065), '\xb5\xfc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 61362), '\xefc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 61362), '\xefc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01')
(('127.0.0.1', 52718), '\xc7\x15\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x05tiles\x08services\x07mozilla\x03com\x00\x00\x01\x00\x01')

但与我预想的不同,我仍然能够打开网站。 Wireshark 告诉我,我正在连接到 8.8.8.8(IDK 怎么样?)。
我尝试从我的机​​器上刷新 DNS Cashe,nada。 我错过了什么?

PPS:如果我删除 try/catch 子句,我会收到此错误(在程序执行几秒钟后):

error: [Errno 10054] An existing connection was forcibly closed by the remote host

【问题讨论】:

  • 您是否在更改设置后重新启动了机器?在使用 google dns 服务器重复相同的请求之前,您是否看到对 localhost 的请求?您可以运行 tshark -i any port 53,查看 dns 请求(tshark 是 Wireshark 的命令行客户端)。
  • @J.F.Sebastian 是的,我重新启动了机器。我无法理解第二部分。还有tshark -i any port 53,一个命令(我对any port部分感到困惑)?
  • 正如我所说,该命令的目的是查看所有 DNS 请求。如果您想知道各个命令行参数的作用; read tshark's man page

标签: python sockets dns udp


【解决方案1】:

您可能已将 Googles 8.8.8.8 配置为备用 DNS 服务器。

并且由于您正在破坏 DNS 答案,因此收到这些损坏答案的人将退回到辅助服务器。在典型的 UN*X 机器上,DNS 查询的整个路径相当复杂,而且整个系统通常非常健壮。

【讨论】:

  • 我使用的是windows机器。有什么办法可以阻止他们使用后备服务器?
  • 另外,输出,它使用名称压缩对吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
  • 2011-08-24
  • 2020-08-17
  • 2021-06-29
  • 1970-01-01
  • 2014-08-12
相关资源
最近更新 更多