title: efficient IP scanner in python
body: <p>trying to do an IP scan in python in a time efficient manner .. I am trying to scan 192.168.0.0/20 and ~1500 hosts are alive .. trying to create something that runs in under a minute of two .. the following is my current code: .. Any suggestions? This code doesn't seem to be very efficient .. </p>
  
  <pre><code>def check_ping(hostname):
    response = os.system("ping -c 1 -W 1 " + hostname+" &gt;/dev/null 2&gt;&amp;1")
    if response == 0:
        print hostname
        pingstatus = True
    else:
        pingstatus = False
  
    return pingstatus
  
  def ipscan():
   output_ip = []
   thehost = "192.168."
   for i in range(0,16):
      host = thehost + str(i) + "."
      for j in  range(0,256):
          newhost = host + str(j)
          output_ip.append(newhost)
          newhost = host
  
    return output_ip
  
  hosts = ipscan()
  num_hosts = len(hosts)
  for k in range(num_hosts):
     temp = hosts[k]
     t=threading.Thread(target=check_ping, args=(temp,))
     t.start()  
  </code></pre>