码迷,mamicode.com
首页 > 编程语言 > 详细

python 批量ping地址

时间:2017-10-24 01:39:25      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:name   coding   __init__   compute   range   not   try   system   tar   

#coding=utf-8
import easygui
import subprocess,os
class PingCmd(object):

def __init__(self):
self.msg = easygui.multenterbox("just compute one net","",["start","end"])
self.part_ip = ".".join(self.msg[0].split(".")[0:3])
self.start_point = self.msg[0].split(".")[-1]
self.end_point = self.msg[-1].split(".")[-1]
self.lis = []

def one_by_one(self):
for i in range(int(self.start_point),int(self.end_point)+1):
self.ip = self.part_ip +"." + str(i)
self.result = os.system("ping -n 1 -w 1 " + self.ip)
if not self.result:
self.lis.append(self.ip)
with open("1.txt","w") as file:
file.write(str("\n".join(self.lis)))
else:
pass

ping = PingCmd()

if __name__ == "__main__":
try:
ping.one_by_one()
except Exception,e:
print e


python 批量ping地址

标签:name   coding   __init__   compute   range   not   try   system   tar   

原文地址:http://www.cnblogs.com/yaxin1989/p/7719881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!