#author: orangleliu date: 2014-11-12#python2.7.x ip_scaner.py ' different platforms, The implementation of IP scanning on the intranet side sometimes needs to know the valid IP of the local area network, but does not want to find a specific tool to scan. How to use python ip_scaner.py 192.168.1.1 (will scan 192.168.1.1-255 IP) ' Import platformimport sysimport osimport timeimport threaddef get_os (): " get os type ' os = Platform.system () if os == "Windows": return "n" else: return "C" def ping_ip (IP_STR): cmd = ["Ping ", "-{op} ". Format (Op=get_os ()), " 1 ", ip_str] output = os.popen (" ". Join (CMD)). ReadLines () flag = false for line in list (output): if not line: continue If str (line). Upper (). Find ("TTL") >=0: flag = true break if flag: print "ip: %s is ok *** "%ip_strdef find_ip (ip_prefix): " gives the current 127.0.0 , and then scans the entire segment for all addresses ' for i in range (1,256): ip = '%s.%s '% (ip_prefix,i) &nBsp; thread.start_new_thread (ping_ip, (IP)) Time.sleep (0.3) if __name__ == "__main__": print "start time %s"%time.ctime () commandargs = sys.argv[1:] args = "". Join (Commandargs) ip_prefix = '. Join (Args.split ('. ') [:-1]) find_ip (Ip_prefix) print "end time %s"% Time.ctime ()
This article is from the "Sanr" blog, make sure to keep this source http://0x007.blog.51cto.com/6330498/1627215
Python scans the intranet for surviving hosts