所以我知道不是所有这些都是正确的,但这就是我所拥有的。我只是想写一个脚本,可以点击谷歌或雅虎,选择1或2和第三个选项,输入一个自定义的URL,如果有人可以帮助我解决这个Id感谢它。
import os
print('1. Ping Google')
print('2. Ping Yahoo')
print('3. Ping custom URL')
key = input('Input your choice: ')
if key == 1:
os.system("ping google.com")
elif key == 2:
os.system("ping yahoo.com")
elif key == 3:
input('Enter URL: ')发布于 2018-02-07 19:17:30
所以我把这个修好了,而且大部分都很管用:
from os import system
print('1. Ping Google')
print('2. Ping Yahoo')
print('3. Ping custom URL')
key = int(input('Input your choice: '))
if key == 1:
system("ping www.google.com")
elif key == 2:
system("ping www.yahoo.com")
elif key == 3:
url = input('Enter URL: ')
system("ping " + url)
else:
print("Invalid Option!")希望这能帮上忙!
发布于 2018-09-26 03:41:29
下面是一个示例代码,它根据任何web地址(如: google.com)的ping状态提供消息。如果响应“确定”,则显示“活动”,否则将显示异常消息。
使用python的Raspberry-pi示例平台:
import requests
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
while True:
try:
response = requests.get('http://google.com')
print(int(response.status_code))
if response.status_code == requests.codes.ok:
GPIO.output(17, GPIO.LOW)
print "ALIVE"
else:
GPIO.output(17, GPIO.HIGH)
print "DISCONNECTED"
time.sleep(1)
except Exception as e:
print "NO INTERNET"
GPIO.output(17, GPIO.HIGH)
print str(e)

发布于 2018-02-07 19:26:08
import os
print('1. Ping Google')
print('2. Ping Yahoo')
print('3. Ping custom URL')
key = input('Input your choice: ')
if key == 1:
os.system("ping google.com")
elif key == 2:
os.system("ping yahoo.com")
elif key == 3:
url=raw_input('Enter URL: ')
os.system("ping %s" %url)
else:
print("invalid input")https://stackoverflow.com/questions/48671518
复制相似问题