python - 为什么我的脚本告诉我无法访问端口 25565 上的 Minecraft 服务器?

标签 python raspberry-pi

我的 Python 脚本无法正常工作。它表示端口 25565 上的 kandicraft.finlaydag33k.nl 已关闭,同时,它正在响应 ping(我可以连接到游戏本身)

我知道这应该是代码某处的错误,但我半小时前启动 python 时找不到它。

我得到的输出是:24-02-2016 16:05:30] 端口 25565 上的 kandicraft.finlaydag33k.nl 似乎无法访问! 我已经编辑了这个问题,因为谷歌的 80 端口现在可以工作了,但是这个脚本的主要目的(ping minecraft 服务器)后来没有。 我从异常中得到的错误是 需要一个整数(所以端口 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)

最佳答案

我设法解决了使用 check_ping(temphost,int(tempport))
发现的所有问题 感谢大家帮我解决!

关于python - 为什么我的脚本告诉我无法访问端口 25565 上的 Minecraft 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35607178/

相关文章:

Java 程序在 raspberry pi 上短时间后无错误地卡住

python-3.x - libwebp.so.6 在 Raspberry Pi 3b 中导入错误

python - 无法安装 rpi_ws281x "error: command ' gcc' 失败,退出状态为 1"

python - 使用 python 单击使用 selenium 的链接

python - 带括号和不带括号的元组之间的区别?

python - 在 Python 中使用多个定界符拆分字符串

python - 通过 Python 运行 Windows CMD 命令

python - NetworkX 测试失败

javascript - Websockets - 多用途与多用途权衡

c++ - CMake交叉编译