Port/ip-get patched

Working issue is the socket will only work for 25565.

!!CAUTION LOTS OF PRINT STATEMENTS!!
This commit is contained in:
Andrew 2021-03-08 22:01:42 -05:00
parent 653a4d6bc7
commit 58f6949fad
3 changed files with 25 additions and 8 deletions

View File

@ -72,7 +72,8 @@ class Player:
# For the rest of requests see wiki.vg/Protocol
def ping(ip, port=25565):
def ping(ip, port):
print("IN PING PORT: " + str(port))
def read_var_int():
i = 0
j = 0
@ -88,11 +89,14 @@ def ping(ip, port=25565):
if not (k & 0x80):
return i
sock = socket.socket()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((ip, port))
print("SOCKET PORT: " + str(port))
sock.connect((ip, int(port)))
except:
pass
print('FALSE 1')
return False
try:
@ -108,8 +112,10 @@ def ping(ip, port=25565):
length = read_var_int() # full packet length
if length < 10:
if length < 0:
print("LEN < 0 FALSE")
return False
else:
print("FALSE 2")
return False
sock.recv(1) # packet type, 0 for pings
@ -118,10 +124,12 @@ def ping(ip, port=25565):
while len(data) != length:
chunk = sock.recv(length - len(data))
if not chunk:
print("NOT CHUNK FALSE")
return False
data += chunk
logger.debug("Server reports this data on ping: {}".format(data))
print("Server reports this data on ping: {}".format(data))
return Server(json.loads(data))
finally:
sock.close()

View File

@ -165,8 +165,10 @@ class Stats:
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server_data.get('server_ip', "127.0.0.1")
server_port = server_settings.get('server_port', "25565")
internal_ip = server_data.get('server-ip', "127.0.0.1")
server_port = server_settings.get('server-port', "25565")
print("PORT!!!!!: " + str(server_port))
logger.debug("Pinging {} on port {}".format(internal_ip, server_port))
int_mc_ping = ping(internal_ip, int(server_port))
@ -207,12 +209,18 @@ class Stats:
p_stats = self._get_process_stats(server_obj.PID)
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server_data.get('server_ip', "127.0.0.1")
server_port = server_settings.get('server_port', "25565")
internal_ip = server_data.get('server-ip', "127.0.0.1")
server_port = server_settings.get('server-port', "25565")
print(str(server_port))
print("Pinging {} on port {}".format(internal_ip, server_port))
logger.debug("Pinging {} on port {}".format(internal_ip, server_port))
int_mc_ping = ping(internal_ip, int(server_port))
print("PING: " + str(int_mc_ping))
int_data = False
ping_data = {}
@ -238,6 +246,7 @@ class Stats:
'desc': ping_data.get("server_description", False),
'version': ping_data.get("server_version", False)
}
print("SERVER STATS LIST LEN(" + str(len(server_stats_list)) + "): ")
# add this servers data to the stack
server_stats_list.append(server_stats)

View File

@ -31,7 +31,7 @@ def do_intro():
console.magenta(intro)
def setup_logging(debug=False):
def setup_logging(debug=True):
logging_config_file = os.path.join(os.path.curdir,
'app',
'config',