Python获取指定网段正在使用的IP
#!/usr/bin/env python# -*- coding: utf-8 -*-’’’’’ 使用方法样例 python test20.py 192.168.1.1 (会扫描192.168.1.1-255的ip) 多线程加速后大概十几秒’’’import platformimport sysimport osimport timeimport threadinglive_ip = 0def 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() for line in output: if str(line).upper().find('TTL') >= 0: print('ip: %s is ok ***' % ip_str) global live_ip live_ip += 1 breakdef find_ip(ip_prefix): ’’’’’ 给出当前的127.0.0 ,然后扫描整个段所有地址 ’’’ threads = [] for i in range(1, 256): ip = ’%s.%s’ % (ip_prefix, i) threads.append(threading.Thread(target=ping_ip, args={ip, })) for i in threads: i.start() for i in threads: i.join()if __name__ == '__main__': print('start time %s' % time.ctime()) cmd_args = sys.argv[1:] args = ''.join(cmd_args) ip_pre = ’.’.join(args.split(’.’)[:-1]) find_ip(ip_pre) print('end time %s' % time.ctime()) print(’本次扫描共检测到本网络存在%s台设备’ % live_ip)
以上就是Python获取指定网段正在使用的IP的详细内容,更多关于python 获取网段ip的资料请关注好吧啦网其它相关文章!
相关文章:
1. IIS Express 取代 ASP.NET Development Server的配置方法2. Spring-Richclient 0.1.0 发布3. Express 框架中使用 EJS 模板引擎并结合 silly-datetime 库进行日期格式化的实现方法4. IntelliJ IDEA设置条件断点的方法步骤5. IntelliJ Idea2017如何修改缓存文件的路径6. Intellij IDEA 旗舰版创建 Spring MVC 项目踩过的坑7. Python使用oslo.vmware管理ESXI虚拟机的示例参考8. Jsp中request的3个基础实践9. python flask框架快速入门10. 浅谈SpringMVC jsp前台获取参数的方式 EL表达式
