Skip to content

Commit d8bebb2

Browse files
WillowSauceRWillowSauceR
authored andcommitted
feat(scan): support set threads used to scan
1 parent 1f9a973 commit d8bebb2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## scan.py
1313

14-
### 使用方法: ``python3 scan.py [目标地址] -i [可选:发包间隔] -p [可选:本地端口] -do [可选:只显示玩家在线数量大于或等于此数值的服务器] -e [在扫描到服务器后立刻执行的cmd命令,需要用双引号包含,具体使用请使用 -h 参数获取帮助] -v6 [使用IPv6协议]``
14+
### 使用方法: ``python3 scan.py [目标地址] -i [可选:发包间隔] -p [可选:本地端口] -t [可选:使用的线程数,默认为CPU核心数减一] -do [可选:只显示玩家在线数量大于或等于此数值的服务器] -e [在扫描到服务器后立刻执行的cmd命令,需要用双引号包含,具体使用请使用 -h 参数获取帮助] -v6 [使用IPv6协议]``
1515

1616
#### 描述: 扫描IP上的所有BE协议服务器
1717

scan.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def progerss_monitor(conn):
5252

5353

5454
is_recving = False
55-
def scanner(udp_skt: socket.socket, addr: str, interval: float):
55+
def scanner(udp_skt: socket.socket, addr: str, interval: float, threads: int):
5656
global is_recving, prog_mon
5757
pbar = tqdm(iterable=range(65536), desc="Scaning progress",
5858
leave=False, unit="Port", unit_scale=False)
@@ -62,7 +62,7 @@ def scanner(udp_skt: socket.socket, addr: str, interval: float):
6262
threading.Thread(target=recv_packets, args=(
6363
udp_skt, pbar), daemon=True).start()
6464

65-
port_ranges = split_list(65536, mp.cpu_count() - 1)
65+
port_ranges = split_list(65536, threads)
6666

6767
parent_conn, child_conn = mp.Pipe()
6868

@@ -131,6 +131,8 @@ def exec_cmd_async(cmd: str, variables: dict = [None]) -> None:
131131
help="send packet interval. recommand 0.01~0.0001")
132132
parser.add_argument("-p", "--port", default=random.randint(1024, 65535), type=int,
133133
help="local port for send packet")
134+
parser.add_argument("-t", "--threads", default=(mp.cpu_count() - 1), type=int,
135+
help="number of threads used to scan")
134136
parser.add_argument("-do", "--display-online", default=0, type=int,
135137
help="only displayed when the number of online players is greater than or equal to this value")
136138
parser.add_argument("-e", "--exec-cmd", default="", type=str,
@@ -148,8 +150,9 @@ def exec_cmd_async(cmd: str, variables: dict = [None]) -> None:
148150
display_online = args.display_online
149151
exec_cmd = args.exec_cmd
150152
use_ipv6 = args.use_ipv6
153+
threads = args.threads
151154

152155
udp_skt = get_udp_socket(local_port, use_ipv6=use_ipv6)
153156

154157
for addr in get_ip_list(addr):
155-
scanner(udp_skt, addr, interval)
158+
scanner(udp_skt, addr, interval, threads)

0 commit comments

Comments
 (0)