python实现批量ping 如何去写

新建两个文本文件,一个保存为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

② 怎样使用python来ping

importos
importre
importtime
importsys
importsubprocess

lifeline=re.compile(r"(d)received")
report=("Noresponse","PartialResponse","Alive")

printtime.ctime()

forhostinrange(1,10):
ip="192.168.1."+str(host)
pingaling=subprocess.Popen(["ping","-q","-c2","-r",ip],shell=False,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
print"Testing",ip,
while1:
pingaling.stdout.flush()
line=pingaling.stdout.readline()
ifnotline:break
igot=re.findall(lifeline,line)
ifigot:
printreport[int(igot[0])]

printtime.ctime()

③ python3 判断IP地址是否ping通

os.system(‘comand’) 会执行括号中的命令,如果命令成功执行,这条语句返回0,否则内返回1。
要想得到标准输出,容可以使用os.popen(cmd)
import os
p=os.popen("ping 192.168.2.129")
x=p.read()
p.close()
if x.count('temeout'):
print("ping不通")
else:
print("ping通了")

④ 使用Python tkinter模块实现ip ping测试

tkinter 动态修改label或者button等控件的文本...label或者button没有setText或者set这样的函数。

⑤ 怎样实现在python中ping域名并返回ip

你可以去网络找些免费资源。目前很多的。如果你有基础的话,完全可以这么做。后盾人上就有好多,我自己还存下来了

⑥ python 怎样去编写一个ping wwww.baidu.com -n 8就是ping之后能带参数的

其实在pip是有一个叫做的ping的项目的,何必折腾自己呢?安装好了后,可以这样简单使用版即可,

importping
ping.verbose_ping(dest_addr,timeout=2,count=4,psize=64)

另外如果要实现权更复杂的东西,还有很多更底层的函数方便你使用。

⑦ python中mysql的ping(True)能实现断开自动重连吗不行的话怎么实现重新连接

conn本来 就已经被你定义成了 函数, conn.ping()当然不存在了。而且你要的数据库连接c,还被手版动关闭了权。我觉得有两点
1. 按照你这个脚本的情况,你用一次,就新建一个数据库连接问题应该不大。
2. 要保持使用一个连接的话。把c作全局变量 c=MySQLdb.connect(user="root",passwd="12345",host="localhost",db="yingtest")
使用的时候,直接用c但是不要close,当然要先判断这个连接是否已经断开了,如是再重新连一次。
或者把连接放到一个连接池里面,用的时候直接去连接池里面取。连接池可以看看 DBUtils模块
你说的conn.ping() 看看是不是在c里面,c=MySQLdb.connect(user="root",passwd="12345",host="localhost",db="yingtest")就是这个对象里面,看看有没有判断连接是否断开的方法。 因为没用过 MySQLdb模块。

⑧ 菜鸟的python代码,请大牛们指教。利用windows自带ping工具对网络进行测试。多多批评,不甚感激。

似乎ping不通啊,实际上是通的啊

⑨ python 执行ping 返回成功与否

代码如下:
import subprocess
import re
p = subprocess.Popen(["ping.exe", 'google.com'],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True)
out = p.stdout.read()
regex = re.compile("Minimum = (\d+)ms, Maximum = (\d+)ms, Average = (\d+)ms", re.IGNORECASE)
print regex.findall(out)