Intranet hosts are automatically assigned IP address, sometimes need to look under the IP in use, wrote a simple script.
Linux and Windows can be used, multi-threaded to ping1-255 all addresses, inefficient, about 2 minutes. Just make it and use it.
#-*-coding:utf-8-*-#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:con tinue if STR (line). Upper (). Find ("TTL") >=0:flag = True if Flag:print "IP :%s is OK * * * * "%ip_strdef find_ip (ip_prefix):" Gives the current 127.0.0, then scans the entire segment all addresses "' for I in Range (1,256): ip = '%s.%s '% (ip_prefix,i) 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 ()
Is the application: Python ip_scaner.py 192.168.31.1 will scan 1-255 of all IP addresses.
D:\codehouse\python\tools>python ip_scaner.py 10.0.1.38start time Wed Nov 18:50:58 2014ip:10.0.1.1 is ok ***ip:10. 0.1.2 is ok ***ip:10.0.1.24 are ok ***ip:10.0.1.38 is ok ***ip:10.0.1.39 is ok ***end time Wed 12 18:52:16 2014
That's it.
This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41048173
Orangleliu
[Pythoncode] Scan the Alive IP address of the LAN