python 批量ping地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 批量ping地址相关的知识,希望对你有一定的参考价值。
#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地址的主要内容,如果未能解决你的问题,请参考以下文章