如题:
import oshostname = str(input('请输入要测试的网域: '))#将输出结果存放到当前目录的response.txt并在后面cat出#ping -count 传送封包4次response = os.system("ping -c 4 %s" %(hostname)+ "> response.txt") #这里如果有回应response将会呈现为状态0if response == 0: print(hostname, 'is working!') os.system("cat response.txt")else: print(hostname, 'is down!')