-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCopenheimer.py
More file actions
70 lines (62 loc) · 2.24 KB
/
Copy pathCopenheimer.py
File metadata and controls
70 lines (62 loc) · 2.24 KB
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
from mcstatus import JavaServer
import logging
import threading
import asyncio
defaultPort = 25565
defaultTimeout = 1
waitForTimeout = 100
ipIters = [
[
#Enter the IP ranges here like this: [[127, 0, 0, 1], [127, 0, 0, 1]],
#A thread will scan each
],
[ # Since computer network buffers are limited, there are different ipIters which are looped over synchronously in order, thus this is the same as the previous one, it just runs afterwards
]
]
outputFileName = "output.txt"
logger = logging.getLogger('log')
logger.setLevel(logging.INFO)
ch = logging.FileHandler(outputFileName)
ch.setFormatter(logging.Formatter('%(message)s'))
logger.addHandler(ch)
def GetAddr(ip):
return f"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}:{defaultPort}"
class SearchThread(threading.Thread):
def __init__(self, ipRange):
threading.Thread.__init__(self)
self.ipRange = ipRange
def run(self):
asyncio.run(self.async_run())
async def async_run(self):
tasks = []
while self.ipRange[0] != self.ipRange[1]:
server = JavaServer.lookup(GetAddr(self.ipRange[0]))
server.timeout = defaultTimeout
tasks.append([self.ipRange[0].copy(), asyncio.create_task(server.async_status())])
self.ipRange[0][3] += 1
for i in reversed(range(len(self.ipRange[0]))):
if self.ipRange[0][i] > 255:
self.ipRange[0][i] = 0
self.ipRange[0][i - 1] += 1
else:
break
for task in tasks:
try:
await asyncio.wait_for(task[1], timeout=waitForTimeout)
task[1].result()
logger.info(GetAddr(task[0]))
except:
pass
print("Thread finished!")
def main():
print("Program started!")
for i in range(len(ipIters)):
print(f"Iteration #{i} started!")
searchThreads = []
for ipRange in ipIters[i]:
searchThreads.append(SearchThread(ipRange))
searchThreads[len(searchThreads) - 1].start()
for thread in searchThreads:
thread.join()
if __name__ == "__main__":
main()