Intranet hosts are their own active allocation of IP addresses, and sometimes need to see those IP in use, wrote a simple script.
Linux and Windows are able to use, multi-threaded to ping1-255 all the addresses, the efficiency is not high. 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 need to know the effective IP of the local area network, but do not want to find a specific tool to scan.Usage python ip_scaner.py 192.168.1.1 (Will scan 192.168.1.1-255 's 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_pref IX = '. '. 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 comes from? " Orangleliu notebook "? Blog. Reprint 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