| 
1 |  | -from multiprocessing.connection import _ConnectionBase  | 
2 | 1 | import socket  | 
3 | 2 | import sys  | 
4 | 3 | import threading  | 
5 | 4 | import time  | 
6 | 5 | import os  | 
7 | 6 | import re  | 
8 |  | -from random import randint  | 
9 | 7 | import multiprocessing as mp  | 
10 |  | -from webbrowser import get  | 
 | 8 | +from random import randint  | 
 | 9 | +from multiprocessing.connection import _ConnectionBase  | 
11 | 10 | 
 
  | 
12 | 11 | from api import getLocalHostIP, getTime, log  | 
13 | 12 | 
 
  | 
 | 
17 | 16 | socketSendRecv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  | 
18 | 17 | socketSendRecv.bind((localHostIP, localHostPort))  | 
19 | 18 | 
 
  | 
20 |  | -scanResult = {"serverCount": 0, "bdsCount": 0, "nkCount": 0, "geyserCount": 0, "skipped": 0, "error": 0, "serverList": [], "totalPlayerCount": 0}  | 
21 |  | - | 
22 |  | -try:  | 
23 |  | -    TargetAddr = sys.argv[1]  | 
24 |  | -    portRange = sys.argv[2]  | 
25 |  | -    verboseMode = sys.argv[3]  | 
26 |  | -except:  | 
27 |  | -    TargetAddr = input("Target IP: ")  | 
28 |  | -    portRange = input("Port range(like 1145-1919 and all): ")  | 
29 |  | -    verboseMode = input("Show verbose info(y/n): ")  | 
30 |  | - | 
31 |  | -try:  | 
32 |  | -    timeout = int(sys.argv[4])  | 
33 |  | -except:  | 
34 |  | -    timeout = 0  | 
35 |  | - | 
36 |  | -try:  | 
37 |  | -    fileName = str(sys.argv[5])  | 
38 |  | -except:  | 
39 |  | -    fileName = ""  | 
 | 19 | +scanResult = {"serverCount": 0, "bdsCount": 0, "nkCount": 0, "geyserCount": 0,  | 
 | 20 | +              "skipped": 0, "error": 0, "serverList": [], "totalPlayerCount": 0}  | 
40 | 21 | 
 
  | 
41 | 22 | motdData = b'\x01\x00\x00\x00\x00$\r\x12\xd3\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x124Vx\n'  | 
42 | 23 | 
 
  | 
@@ -114,7 +95,9 @@ def startThreads():  | 
114 | 95 |         t1.join()  | 
115 | 96 |         # while threading.enumerate().__len__() != 2:  # main and itself  | 
116 | 97 |         #     time.sleep(1)  | 
117 |  | - | 
 | 98 | +    # while mp.active_children():  | 
 | 99 | +    #     time.sleep(1)  | 
 | 100 | +    # mp.active_children()[0].terminate()  | 
118 | 101 |     log(f"BE Server Count: {scanResult['serverCount']}", info="I")  | 
119 | 102 |     log(f"BDS Count: {scanResult['bdsCount']}", info="I")  | 
120 | 103 |     log(f"NK Count: {scanResult['nkCount']}", info="I")  | 
@@ -190,22 +173,42 @@ def recvPackets(socketSendRecv: socket.socket, verboseMode: str, fileName: str,  | 
190 | 173 |             elif re.search(b"eyser", data):  | 
191 | 174 |                 scanResult['geyserCount'] += 1  | 
192 | 175 |             # socketSendRecv.close()  | 
193 |  | -            pipe.send(scanResult)  | 
194 | 176 |         except OSError as errorInfo:  | 
195 | 177 |             if verboseMode == "y":  | 
196 | 178 |                 log(f"{errorInfo}, skipped.", info="R")  | 
197 | 179 |             scanResult['error'] += 1  | 
198 | 180 |         except Exception as errorInfo:  | 
199 | 181 |             log(f"{errorInfo}, skipped.", info="R")  | 
200 | 182 |             scanResult['error'] += 1  | 
201 |  | -            pass  | 
 | 183 | +        finally:  | 
 | 184 | +            pipe.send(scanResult)  | 
202 | 185 | 
 
  | 
203 | 186 | 
 
  | 
204 | 187 | if __name__ == "__main__":  | 
205 |  | -    t = threading.Thread(target=startThreads, daemon=True)  | 
206 |  | -    t.start()  | 
 | 188 | +    try:  | 
 | 189 | +        TargetAddr = sys.argv[1]  | 
 | 190 | +        portRange = sys.argv[2]  | 
 | 191 | +        verboseMode = sys.argv[3]  | 
 | 192 | +    except:  | 
 | 193 | +        TargetAddr = input("Target IP: ")  | 
 | 194 | +        portRange = input("Port range(like 1145-1919 and all): ")  | 
 | 195 | +        verboseMode = input("Show verbose info(y/n): ")  | 
 | 196 | + | 
 | 197 | +    try:  | 
 | 198 | +        timeout = int(sys.argv[4])  | 
 | 199 | +    except:  | 
 | 200 | +        timeout = 0  | 
 | 201 | + | 
 | 202 | +    try:  | 
 | 203 | +        fileName = str(sys.argv[5])  | 
 | 204 | +    except:  | 
 | 205 | +        fileName = ""  | 
 | 206 | + | 
207 | 207 |     pipe1, pipe2 = mp.Pipe()  | 
208 |  | -    p = mp.Process(target=recvPackets, args=(socketSendRecv, verboseMode, fileName, scanResult, pipe2), daemon=True)  | 
 | 208 | +    p = mp.Process(target=recvPackets, args=(  | 
 | 209 | +        socketSendRecv, verboseMode, fileName, scanResult, pipe2), daemon=True)  | 
209 | 210 |     p.start()  | 
 | 211 | +    t = threading.Thread(target=startThreads, daemon=True)  | 
 | 212 | +    t.start()  | 
210 | 213 |     while mp.active_children():  | 
211 |  | -        scanResult = pipe2.recv()  | 
 | 214 | +        scanResult = pipe1.recv()  | 
0 commit comments