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, to achieve IP scanning on the intranet side sometimes need to know where The effective IP of the LAN, but do not want to find specific tools to scan. How to use Python ip_scaner.py 192.168.1.1 (will scan 192.168.1.1-255 IP) ' Import platform import sys import OS import time Import Thread Def 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). Up Per (). Find ("TTL") >=0:flag = True break if Flag:print "IP:%s is OK * * * *"%ip_str def find_ip (ip_pre Fix): "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) thread.start_n Ew_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.
That's it.