-
Notifications
You must be signed in to change notification settings - Fork 37
/
mcscanner.py
87 lines (67 loc) · 2.72 KB
/
mcscanner.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
75
76
77
78
79
80
81
82
83
84
85
86
87
from mcstatus import JavaServer
import os
import math
import threading
import time
import argparse
parser = argparse.ArgumentParser(description='get files for procesing')
parser.add_argument("-i", "--inputfile", type=str, help="put in the file with all the server IP's")
parser.add_argument("-o","--outputfile", type=str, help="the name of the file to put in the results")
parser.add_argument("-p","--publicserverlist", type=str, help="put in the file with the public server list (public.txt)")
parser.add_argument("-v","--version", type=str, default="", required=False, help="you can specify the minecarft server you wanna find")
args = parser.parse_args()
masscan = []
print('Multithreaded mass minecraft server status checker by Footsiefat/Deathmonger')
time.sleep(1)
inputfile = args.inputfile
outputfile = args.outputfile
publicserverlist = args.publicserverlist
searchterm = args.version
outfile = open(outputfile, 'a+')
outfile.close
fileHandler = open (inputfile, "r")
listOfLines = fileHandler.readlines()
fileHandler.close()
for line in listOfLines:
if line.strip()[0] != "#":
masscan.append(line.strip().split(' ',4)[3])
def split_array(L,n):
return [L[i::n] for i in range(n)]
threads = int(input('How many threads do you want to use? (Recommended 20): '))
time.sleep(2)
if len(masscan) < int(threads):
threads = len(masscan)
split = list(split_array(masscan, threads))
exitFlag = 0
class myThread (threading.Thread):
def __init__(self, threadID, name):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
def run(self):
print ("Starting Thread " + self.name)
print_time(self.name)
print ("Exiting Thread " + self.name)
def print_time(threadName):
for z in split[int(threadName)]:
if exitFlag:
threadName.exit()
try:
ip = z
server = JavaServer(ip,25565)
status = server.status()
except:
print("Failed to get status of: " + ip)
else:
print("Found server: " + ip + " " + status.version.name + " " + str(status.players.online))
if searchterm in status.version.name:
with open(outputfile) as f:
if ip not in f.read():
with open(publicserverlist) as g:
if ip not in g.read():
text_file = open(outputfile, "a")
text_file.write(ip + " " + status.version.name.replace(" ", "_") + " " + str(status.players.online))
text_file.write(os.linesep)
text_file.close()
for x in range(threads):
thread = myThread(x, str(x)).start()