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)