Python implementation scan LAN active IP (scan online PC)

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.