介绍
利用Python怎么获取指定网段的IP ?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
实现方法如下:
# !/usr/bin/env Python #,- *安康;编码:utf-8 - * - & # 39;& # 39;& # 39;& # 39;& # 39;, 使用方法样例,python test20.py 192.168.1.1 (会扫描192.168.1.1-255的ip), 多线程加速后大概十几秒 & # 39;& # 39;& # 39; import 平台 import 系统 import 操作系统 import 时间 import 线程 live_ip =0 def get_os (): 时间=os 才能;platform.system () if 才能;os ==,“Windows": ,,,return “n" 其他的才能: ,,,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 拷贝输出: ,,,if str(线).upper (); (“TTL"),祝辞=,0: ,,,,,印刷(“ip: % s is ok * * *“, %, ip_str) ,,,,,global live_ip ,,,,,live_ip +=1 ,,,,,休息 def find_ip (ip_prefix): & # 39;才能& # 39;& # 39;& # 39;& # 39; 给才能出当前的127.0.0 ,然后扫描整个段所有地址 & # 39;才能& # 39;& # 39; 时间=threads 才能;[] for 才能小姐:拷贝范围(1,256): ,,,ip =, & # 39; % s % & # 39;, %, (ip_prefix,,我) ,,,threads.append (threading.Thread(目标=ping_ip, arg游戏={ip,,})) for 才能小姐:拷贝线程: ,,,i.start () for 才能小姐:拷贝线程: ,,,i.join () if __name__ ==,“__main__": 打印才能(“start  time % s", %, time.ctime ()) 时间=cmd_args 才能;sys.argv [1:] args 才能=,,,. join (cmd_args) 时间=ip_pre 才能;& # 39;强生# 39;. join (args.split(& # 39; # 39;公司)[1]): find_ip才能(ip_pre) 打印才能(“最终获得time % s", %, time.ctime ()) 打印才能(& # 39;本次扫描共检测到本网络存在% s台设备& # 39;,%,live_ip)
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。