1. 程式人生 > >python 批量ping地址

python 批量ping地址

split poi __main__ with Coding self init print system

#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地址