title: Send DNS request with socket in Python
body: <p>Here is what I am trying to do :</p>
  
  <p>I send a <strong>DNS request</strong> (with dig or whatever), and I intercept it with <strong>socket</strong> in python. Then, I want to send this same request to the gateway, and wait for the response from the gateway.</p>
  
  <pre><code>import socket
  
  #I redirected all DNS requests from port 53 to port 2525 so I am listening here
  port = 2525
  ip = '127.0.0.1'
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  sock.bind((ip, port))
  
  #Gateway part
  gateway = '192.168.1.1' 
  port_gateway = 9090
  
  sock_gateway = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  sock_gateway.connect((gateway, port_gateway))
  
  while 1:
      data, addr = sock.recvfrom(512)
  
      print(data)
      #send the request from User to the gateway :
      sock_gateway.sendto(data, (gateway, 53))
  
      reply = sock_gateway.recv(512)
  
      print(reply)
  </code></pre>
  
  <p>Here is the output : <code>b'7\xa3\x01 \x00\x01\x00\x00\x00\x00\x00\x01\x06google\x03com\x00\x00\x01\x00\x01\x00\x00)\x10\x00\x00\x00\x00\x00\x00\x0c\x00\n\x00\x08\x9b+\xc1\xfa\xf4\xbc\x1c\x14'</code></p>
  
  <p>This is the data from the DNS request I made, but then, I want to forward it to the gateway, and to listen to the response, but it doesn't get any response.</p>
  
  <p>How can I do that ?</p>