-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsteam_list.py
70 lines (58 loc) · 1.74 KB
/
steam_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
""" Steam communication
Methods:
getServerListSteam(ip_list : string) : list
getServerInfoSteam(ip, steam_port) : dictionary
By: github.com/iamflea
Licence: who cares July 2019
"""
import socket
import http.client
import json
from steam import game_servers as gs
from config import *
#QUERY_STEAM_APP = r'\appid\322330'
''' Get all servers having `ip` '''
# https://94.76.229.42
def getServerListSteam(ip):
# Connect
conn = http.client.HTTPSConnection('api.steampowered.com', 443)
conn.request("GET", f'/ISteamApps/GetServersAtAddress/v1/?addr={ip}')
res = conn.getresponse()
# Check if everything is all right
if res.status != 200:
return []
# Get data and close connection
data = res.read()
conn.close()
# Get json data
data = json.loads(data)
try:
servers = data['response']['servers']
except (KeyError, IndexError):
return []
for s in servers:
#print(s)
try:
if s['appid'] == 322330:
ip, port = s['addr'].split(':')
yield (ip, int(port), int(s['gameport']))
except (KeyError, IndexError, ValueError):
continue
""" Get steam info
@param `ip` string, IP address
@param `port` int, port for STEAM (not same as DST port)
"""
def getServerInfoSteam(ip, port):
#print("getServerInfoSteam()")
server = (ip, int(port))
return {"info": gs.a2s_info(server),
"players": gs.a2s_players(server),
"rules": gs.a2s_rules(server)}
if __name__ == '__main__':
#import print
DFT = '94.76.229.42'
DST_EU = '46.101.212.23'
x = getServerListSteam(DFT)
t = list(x)
print("---")
print(t)