我的Python腳本無法正常工作。它說端口25565
上的kandicraft.finlaydag33k.nl
已關閉,同時它響應Ping(我可以連接到遊戲本身)爲什麼我的腳本告訴我端口25565上的我的Minecraft服務器無法訪問?
我知道它應該是代碼中某處的錯誤,但我找不到它作爲我在半小時前開始使用python。
我得到的輸出是:24-02-2016 16:05:30] kandicraft.finlaydag33k.nl on port 25565 seems to be unreachable!
我已經編輯了與谷歌現在的80端口的問題,但此腳本的主要目的(ping通minecraft服務器)不會。 我從異常得到的錯誤是an integer is required
(所以端口25565
似乎不爲整數???)
import os
import RPi.GPIO as gpio
import time
import socket
## set variables for the machine to ping and pin for the LED
hostname = ['kandicraft.finlaydag33k.nl:25565','google.com:80']
led_pin = 37
## prepare
led_status = gpio.LOW
gpio.setmode(gpio.BOARD)
gpio.setup(led_pin, gpio.OUT, gpio.PUD_OFF, led_status)
## PING FUNCTION GALORE!!
def check_ping(host,port):
captive_dns_addr = ""
host_addr = ""
try:
host_addr = socket.gethostbyname(host)
if (captive_dns_addr == host_addr):
return False
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect((host,port))
s.close()
except:
return False
return True
## Run the script itself infinitely
while True:
host_up = ""
for host in hostname:
if ":" in host:
temphost, tempport = host.split(":")
pingstatus = check_ping(temphost, tempport)
if pingstatus == False:
print('[' + time.strftime("%d-%m-%Y %H:%M:%S") + '] ' + temphost + ' on port ' + tempport + ' seems to be unreachable!')
host_up = "False"
if host_up == "False":
led_status = gpio.HIGH
else:
led_status = gpio.LOW
gpio.output(led_pin,led_status)
time.sleep(1)
請勿將鏈接發佈到代碼,請在問題中發佈代碼。 –
請發佈您的程序返回的輸出 – mvelay
哇!對於「半小時前開始使用Python」的人來說,你的表現相當不錯。或者別人寫了那個代碼......? –