2013-11-03 19 views
-1

我需要掃描網絡上的每臺主機,以查看它們是否使用python在端口80上託管web服務器。我寫了一個腳本來做到這一點,但它的效率令人難以置信。是否有可以更有效地做這個任務Python掃描網絡上的所有主機

def scanhosts(): 
    for ifaceName in interfaces(): 
     addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}])] 
     if ifaceName == "wlan0": 
      return ', '.join(addresses) 

def scanlooper(subnet): 
    for i in range(0,1): 
     for x in range(0,999): 
      s = "%s.%s.%s" % (subnet,i,x) 
      request = urllib2.Request('http://%s/' % s) 
      try: 
       response = urllib2.urlopen(request) 
       html = response.read() 
       if html != "False": 
        print "%s is hosting a server" % s 
      except: 
       print "%s is not hosting a server" % s 

localip = scanhosts() 
ipstrip = localip.strip(".") 
subnet = "%s.%s" % (ipstrip[0],ipstrip[1]) 
scanlooper(subnet) 

顯然沒有執行這個任務,從1'000'000潛在主機下載頁面難言有效的更好的辦法任何模塊或庫。

感謝

+0

這個問題Python綁定可能適合http://codereview.stackexchange.com – aIKid

回答

3

檢查出nmap

+0

不應該這是一個註釋? – aIKid

+2

這是正確的 –

+0

我想使用nmap模塊,但我無法掃描所有子網(主機可能存在於172.20。*。*中),我不認爲nmap有能力掃描所有主機。 – user2330561