Python scans the intranet for surviving hosts

Source: Internet
Author: User

#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&nbsp, 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

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.