標籤:python return import
#author: orangleliu date: 2014-11-12#python2.7.x ip_scaner.py‘‘‘不同平台,實現對所在內網端的ip掃描有時候需要知道所在區域網路的有效ip,但是又不想找特定的工具來掃描。使用方法 python ip_scaner.py 192.168.1.1 (會掃描192.168.1.1-255的ip)‘‘‘import platformimport sysimport osimport timeimport threaddef get_os(): ‘‘‘ get os 類型 ‘‘‘ 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): ‘‘‘ 給出當前的127.0.0 ,然後掃描整個段所有地址 ‘‘‘ 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()
本文出自 “Sanr” 部落格,請務必保留此出處http://0x007.blog.51cto.com/6330498/1627215
python 掃描內網存活主機