-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrawl.py
74 lines (60 loc) · 3.27 KB
/
crawl.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
71
72
73
74
import os
import time
import json
import urllib.request
scan_endpoint = [
'http://143.198.104.205/servers.php?central=anygenre1.jamulus.io:22124',
'http://143.198.104.205/servers.php?central=anygenre2.jamulus.io:22224',
'http://143.198.104.205/servers.php?central=anygenre3.jamulus.io:22624',
'http://143.198.104.205/servers.php?central=rock.jamulus.io:22424',
'http://143.198.104.205/servers.php?central=jazz.jamulus.io:22324',
'http://143.198.104.205/servers.php?central=classical.jamulus.io:22524',
'http://143.198.104.205/servers.php?central=choral.jamulus.io:22724',
]
# this script runs on jf, which doesn't have a probe onboard.
print("only run this during severe lulls. quit now if it's not a lull.")
time.sleep(5)
while True:
probe = ""
isLoungeFree = str(urllib.request.urlopen("http://hear.jamulus.live/free.txt").readline().decode('utf-8').strip())
if isLoungeFree == "True":
probe = "hear"
# else:
# isRadioFree = str(urllib.request.urlopen("http://radio.jamulus.live/free.txt").readline().decode('utf-8').strip())
# if isRadioFree == "True":
# probe = "radio"
if probe == "":
print("no probes available.")
exit()
print("using " + probe + ".jamulus.live recklessly.")
# since i can't run the probe for a long time, i'll just do one probe and quit.
for url in scan_endpoint:
data = json.loads(urllib.request.urlopen(url).read())
for server in data:
# WE EVEN CRAWL POPULATED SERVERS, HENCE WE ONLY RUN DURING SEVERE LULL
# if 'clients' in server:
# continue
# we found a server that has no clients on it right now.
ipPort = server['ip'] + ":" + str(server['port'])
# is it on the denylist?
denylist = str(urllib.request.urlopen("https://jamulus.live/cannot-dock.txt").read())
if denylist.find(ipPort) != -1: # on denylist.
continue
# is it on the allowlist?
allowlist = str(urllib.request.urlopen("https://jamulus.live/can-dock.txt").read())
if allowlist.find(ipPort) != -1: # on allowlist.
continue
# Request a probe by writing my location on the lounge server.
print("Probing " + ipPort + " aka " + server['name'])
DEPLOYMENT_REQUEST_FILE = "/root/JamFan22/JamFan22/wwwroot/requested_on_" + probe + ".txt"
os.system("sudo sh -c 'echo " + ipPort + " > " + DEPLOYMENT_REQUEST_FILE + "'")
time.sleep(120) # wait for the probe to arrive. wait a super long time.
didlobbyarrive = str(urllib.request.urlopen("http://143.198.104.205/servers.php?server=" + ipPort).read())
if didlobbyarrive.find("obby") != -1:
print("probe succeeded.")
os.system("sudo sh -c 'echo " + ipPort + " >> /root/JamFan22/JamFan22/wwwroot/can-dock.txt'") # add to allowlist
# os.system("sudo sh -c 'echo 127.0.0.1 > " + DEPLOYMENT_REQUEST_FILE + "'") # don't leave this probe hanging
else:
print("probe failed.")
os.system("sudo sh -c 'echo " + ipPort + " >> /root/JamFan22/JamFan22/wwwroot/cannot-dock.txt'") # add to denylist
exit() # time.sleep(60) # just unclear about speed.