title: Why is port scanning with python sockets so much slower on Windows than it is on linux?
body: <p>I've tried looking around online through different python docs, forums, and other people's questions but I haven't found anyone with this same question.</p>
  
  <p>What my scripts typically look like is I'll create a socket connection that tries connecting to ports 1-9999 and will only tell me when a port is open. When I run this on windows it takes 1 second to scan a port before moving on to the next one (60 ports/m. ~16.5m for 1000 ports). When I run the same scripts on linux, it'll cycle through all 9999 ports very quickly, while still returning the same desired results. </p>
  
  <p>I was hoping to be able to build cross-compatible tools, but it appears linux 
   is just the better operating system when it comes to my networking needs? I have both at my disposal so I don't mind using one over the other. I'd just like to know if there's anything that could be done to make port scanning almost as equally fast on both operating systems, otherwise I won't spend as much time building on/for windows. </p>
  
  <p>The difference in speed is the same regardless of which network I'm on.</p>
  
  <p>My questions are:<br>•Why is the performance so different on windows compared to linux when given the same functions?<br>•Is there anything that can be done to make port scanning with sockets faster like it is on linux? </p>
  
  <p>--edit--</p>
  
  <p>here's the piece I use to check ports</p>
  
  <pre><code>def whole_scan(Host_):
      service = ''
      host = Host_
      max_port = 9999
      min_port = 1
      def scan_host(host, port, r_code = 1):
          try:
              s = socket(AF_INET, SOCK_STREAM)
              code = s.connect_ex((host, port))
              if code == 0:
                  r_code = code
                  s.close()
          except Exception, e:
              pass
          return r_code
          hostip = gethostbyname(host)
      for port in range(min_port, max_port):
          try:
              response = scan_host(host,port)
              if response == 0:
                  try:
                      service = getservbyport(port)
                  except Exception, e:
                      service = 'n/a'
              print(" |--port: %d\t%s" % (port,service.upper()))
          except Exception, e:
              pass
  </code></pre>
  
  <p>I've also verified my firewall is disabled and adding the value to my registry to disable the limit on connections had no change on performance. I'm on windows 10.</p>