title: How to send multiple threads for Nmap scanning in python?
body: <p>I have a small code, and what it will do, it will find the nmap port scans through Python.</p>
  
  <pre><code>st = time.time()
  
  urls_returning200 = []
  urls_returning400 = []
  
  
  
  urls_returning200.append('http://192.168.0.2')
  urls_returning400.append('http://192.168.0.3')
  
  
  ftpurls = []
  
  
  def nmapscan(ur):
  
      try:
          nm.scan(ur, '20-25')
          for host in nm.all_hosts():
              print "\nHost: {0} ({1})"  .format(host, nm[host].hostname()) 
              print "Host State:  %s" % nm[host].state()
  
  
              for proto in nm[host].all_protocols():
                  port = nm[host][proto].keys()
                  port.sort()
                  print "\nPort      State     Service"
                  for ports in port:
  
                      print "{0}     {1}    {2}" .format(ports, nm[host][proto][ports]['state'], nm[host][proto][ports]['name'])
  
      except KeyError as e:
          print "[!] Cannot scan host!: " + ur + "\n" 
  
  
  
  
  print "\n...............................................................................................\n"     
  print "\n                                                 [PHRASE: 4]: Starts below                                                \n\n"        
  
  
  nm = nmap.PortScanner()
  
  
  
  def nm1():
      global lock
      lock.acquire()
      print time.time()
  
      try:
          print "\n[!]Finding the Ports stats of 200's URL's \n"
          for x in set(urls_returning200):
              newurl = x.replace('http://', '') 
              nmapscan(newurl)
  
      finally:
          lock.release()
  
  
  
  def nm2():
      global lock
      lock.acquire()
      print time.time()
  
      try:
          print "\n...............................................................................................\n"
          print "\n[!]Finding the Ports stats of 400's URL's \n"
          for x in set(urls_returning400):
              newurl1 = x.replace('http://', '') 
              nmapscan(newurl1)
  
      finally:
          lock.release    
  
  
  lock = threading.Lock()     
  if __name__ == '__main__':
      th  = threading.Thread(target=nm1)
      th.start()
      th1 = threading.Thread(target=nm2)
      th1.start()
      th1.join
  
      print "overall time has been ", time.time()- st     
  </code></pre>
  
  <p>Now I have defined 2 functions <code>nm1</code> and  <code>nm2</code> and another function i.e. <code>nmapscan</code> for scanning the defined URLs which are given by the <code>nm1</code> and <code>nm2</code>. And I have defined the time at the top of both functions for getting on which <strong>time the thread starts</strong>. And then I defined two threads i.e. <code>th</code>, <code>th1</code>. And I want both threads to start at the same time</p>
  
  <p>Now the problem is,</p>
  
  <p><strong>I can not send the both threads at the same time, You can see the time of both of the functions</strong></p>
  
  <pre><code>1529037892.08 // time of the first function.
  [!]Finding the Ports stats of 200's URL's
  
  
  Host: 192.168.0.2 ()
  Host State:  up
  
  Port      State     Service
  20     closed    ftp-data
  21     closed    ftp
  22     closed    ssh
  23     closed    telnet
  24     closed    priv-mail
  25     closed    smtp
  
  ...............................................................................................
  
  1529037904.75 // Time of the second function,
  
  [!]Finding the Ports stats of 400's URL's
  
  
  Host: 192.168.0.4
  Host State:  up
  
  
  overall time has been  31.6859998703
  </code></pre>
  
  <p>Now, I have check the code so many times but I didn't found the problem.</p>