python实现扫描ip地址的小程序
python实现扫描ip地址的小程序,具体代码如下所示:
import os,time import sys start_Time=int(time.time()) ip_True = open('ip_True.txt','w+') ip_False = open('ip_False.txt','w+') IPhost = [] IPbegin = (input(u'请输入起始查询IP: ')) IPend = input(u'请输入终止查询IP: ') IP1 = IPbegin.split('.')[0] IP2 = IPbegin.split('.')[1] IP3 = IPbegin.split('.')[2] IP4 = IPbegin.split('.')[-1] IPend_last = IPend.split('.')[-1] count_True,count_False = 0,0 for i in range(int(IP4)-1,int(IPend_last)): ip = str(IP1+'.'+IP2+'.'+IP3+'.'+IP4) int_IP4 = int(IP4) int_IP4 += 1 IP4 = str(int_IP4) return1=os.system('ping -n 1 -w 1 %s'%ip) if return1: print('ping %s is fail'%ip) ip_False.write(ip+'\n') count_False += 1 else: print('ping %s is ok'%ip) ip_True.write(ip+'\n') count_True += 1 ip_True.close() ip_False.close() end_Time = int(time.time()) print("time(秒):",end_Time - start_Time,"s") print("ping通的ip数:",count_True," ping不通的ip数:",count_False)
总结
以上所述是小编给大家介绍的python实现扫描ip地址的小程序,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对安科网网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16