python实现扫描ip地址的小程序-创新互联

python实现扫描ip地址的小程序,具体代码如下所示:

创新互联公司是一家专注于成都网站设计、网站制作、外贸营销网站建设与策划设计,阜新网站建设哪家好?创新互联公司做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:阜新等地区。阜新做网站价格咨询:18980820575
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地址的小程序-创新互联
本文来源:http://myzitong.com/article/dhpcdh.html