iT邦幫忙

0

簡易練習-4 ping網址

如題:

import os
hostname = str(input('請輸入要測試的網域: '))
#將輸出結果存放到當前目錄的response.txt並在後面cat出
#ping -count 傳送封包4次
response = os.system("ping -c 4 %s" %(hostname)+ "> response.txt") 
#這裡如果有回應response將會呈現為狀態0
if response == 0:
    print(hostname, 'is working!')
    os.system("cat response.txt")
else:
    print(hostname, 'is down!')

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言