第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 ping 上抑制終端輸出,但仍然能夠驗證響應(yīng)?

如何在 ping 上抑制終端輸出,但仍然能夠驗證響應(yīng)?

紅糖糍粑 2022-01-11 17:00:28
因此,每當我發(fā)送數(shù)據(jù)包時,我一直在努力抑制終端輸出。我只想驗證響應(yīng)(0,2 或其他),這樣我的終端就不會收到標準的“ping 統(tǒng)計信息、收到的數(shù)據(jù)包、數(shù)據(jù)包丟失”的垃圾郵件。我將如何在代碼方面進行此操作?我不是在尋找終端/bash“方式”。def ping():    hosts = open('hosts.txt', 'r')    for host_ip in hosts:       res = subprocess.call(['ping', '-c', '1', host_ip])       if res == 0:          print "ping to", host_ip, "OK"       elif res == 2:          print "no response from", host_ip       else:          print "ping to", host_ip, "failed!"
查看完整描述

1 回答

?
牛魔王的故事

TA貢獻1830條經(jīng)驗 獲得超3個贊

我只是使用 python 的subprocess.Popen類ping 到 google dns 服務(wù)器,除了我在代碼中打印的返回碼之外,它什么都不返回到終端


import subprocess

process = subprocess.Popen(['ping','-c' ,'1', '8.8.8.8'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

stdout, stderr = process.communicate()

returncode = process.returncode

print(returncode)

輸出


0


查看完整回答
反對 回復(fù) 2022-01-11
  • 1 回答
  • 0 關(guān)注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號