python实现批量ping 如何去写

python实现批量ping 如何去写,第1张

新建两个文本文件,一个保存为test.bat,一个保存为test.txt,两文件保存在一拦吵态个文件夹下碰段 test.txt的内容 192.168.0.29 127.1 test.bat的内容 @echo off echo 正在ping网址简源,请稍候…… for /f %%i in (test.txt) do ping %%i /n 10 >>hello.txt s

import os

import re

import time

import sys

import subprocess

 

lifeline = re.compile(r"(\d) received")

report = ("No response","Partial Response","Alive")

 

print time.ctime()

 

for host in range(1,10):

   ip = "带顷并192.168.1."+str(host)

   pingaling = subprocess.Popen(["ping","-q", "-c 2", "-r", ip], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

   print "Testing ",ip,

   while 1:

      乎胡pingaling.stdout.flush()

      line = pingaling.stdout.readline()

      if not line: break

      蠢迹igot = re.findall(lifeline,line)

      if igot:

           print report[int(igot[0])]

 

print time.ctime()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12295267.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存