title: Python is a bit slow. How can I speed up this code?
body: <p>Python is disappointing me. I searched a code for port scan, found this. Runned it. the program I used for scanning. It was very fast according to python code. the code is below.<br>
  Can you help me about accelerating my code. What can i du for it?.</p>
  
  <pre><code>#!/usr/bin/env python  
  from socket import *   
  
  if __name__ == '__main__':  
      target = raw_input('Enter host to scan: ')  
      targetIP = gethostbyname(target)  
      print 'Starting scan on host ', targetIP  
  
      #scan reserved ports  
      for i in range(20, 1025):  
          s = socket(AF_INET, SOCK_STREAM)  
  
          result = s.connect_ex((targetIP, i))  
  
          if(result == 0) :  
              print 'Port %d: OPEN' % (i,)  
          s.close()
  </code></pre>