title: Python UDP Port Knocker - Not Working
body: <p>I want to code a UDP Port Knocker. I have 5 possible UDP ports 2222,3333,4444,5555,6666 and I should knock this ports on a certain IP address, if the knock sequence is correct (e.g. 3333,4444,2222) I can talk to the server via TCP and it will give me an answer. Otherwise no answer and no connection.</p>
  
  <p>Why does my code not work? The 'x' in the code mark places where normally private information are put in - no syntax errors.</p>
  
  <pre><code>import socket
  import time
  
  UDP_IP = "xxxxx"
  TCP_IP = 'xxxxx'
  TCP_PORT = 1111
  
  request = "xxx"
  
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  d = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  def my_range(start, end, step):
      while start &lt;= end:
          yield start
          start += step
  
  for x in my_range(2222, 6666, 1111):
      for y in my_range(2222, 6666, 1111):
          for z in my_range(2222, 6666, 1111):
              print "Port knock: ",x,y,z
              s.sendto(request,(UDP_IP, x))
              s.sendto(request,(UDP_IP, y))
              s.sendto(request,(UDP_IP, z))
              print "Waiting..."
              time.sleep(1)
              try:
                  d.connect((TCP_IP, TCP_PORT))
                  print "SUCCESS:",x,y,z
                  time.sleep(1)
                  data = d.recv(1024)
                  print "Servers says: " + data
              except socket.error:
                  print "False combination of ports"
                  continue
  s.close()
  d.close()
  </code></pre>