-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
29 lines (25 loc) · 846 Bytes
/
main.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
import ipaddress
from concurrent.futures import ThreadPoolExecutor
import mcstatus
import json
import time
def save_server(information: str, ip):
file = open(r'servers.json')
data = json.load(file)
data[ip] = information
json.dump(data, open('servers.json', 'w'))
def check_mc(ip):
try:
server_status = mcstatus.JavaServer.lookup(ip).status()
print(f"The ip {ip} has a Minecraft server with {server_status.latency}ms ping")
save_server(server_status.raw, ip)
except Exception as e:
print(ip, e)
def main():
cidr = input('Enter the cidr that you want to scan! ')
ips = [str(ip) for ip in ipaddress.IPv4Network(cidr)]
with ThreadPoolExecutor(max_workers=400) as executor:
for ip in ips:
executor.submit(check_mc, ip)
if __name__ == '__main__':
main()