创建DNS服务器并将所有请求重定向到我的站点

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

我想在我的路由器中更改DNS服务器和DNS服务器,我希望每个请求都返回相同的站点。基本上我需要添加更多逻辑,以确保DNS响应的答案。我不想从头开始编写DNS。你有什么建议吗?也许,我可以轻松改变的开源DNS(מo what what language-c,cpp,python,java ...)(如果是,哪一个和哪里)

  • 我可以用google-cloud-dns吗?

谢谢。

dns server router google-cloud-dns
1个回答
3
投票

看看这里:http://code.activestate.com/recipes/491264-mini-fake-dns-server/这是一个Python脚本,它看起来就像你需要的那样。

import socket

class DNSQuery:
  def __init__(self, data):
    self.data=data
    self.dominio=''

    tipo = (ord(data[2]) >> 3) & 15   # Opcode bits
    if tipo == 0:                     # Standard query
      ini=12
      lon=ord(data[ini])
      while lon != 0:
        self.dominio+=data[ini+1:ini+lon+1]+'.'
        ini+=lon+1
        lon=ord(data[ini])

  def respuesta(self, ip):
    packet=''
    if self.dominio:
      packet+=self.data[:2] + "\x81\x80"
      packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00'   # Questions and Answers Counts
      packet+=self.data[12:]                                         # Original Domain Name Question
      packet+='\xc0\x0c'                                             # Pointer to domain name
      packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04'             # Response type, ttl and resource data length -> 4 bytes
      packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
    return packet

if __name__ == '__main__':
  ip='192.168.1.1'
  print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip

  udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  udps.bind(('',53))

  try:
    while 1:
      data, addr = udps.recvfrom(1024)
      p=DNSQuery(data)
      udps.sendto(p.respuesta(ip), addr)
      print 'Respuesta: %s -> %s' % (p.dominio, ip)
  except KeyboardInterrupt:
    print 'Finalizando'
    udps.close()

问候。

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