首页 > 代码库 > <script>网络主机扫描(ping)
<script>网络主机扫描(ping)
#!/usr/bin/env python #-*- coding: UTF-8 -*- import platform import sys import os import time import thread def get_os(): # get os os = platform.system() if os == "Windows": return "n" else: return "c" def ping_ip(ip_str): #ping ip 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_str def find_ip(ip_prefix): #find all ip of the net 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()
本文出自 “天下皆白,哼” 博客,请务必保留此出处http://xiaoqin00.blog.51cto.com/10468367/1917168
<script>网络主机扫描(ping)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。