Skip to content

Commit 6c6e0ab

Browse files
committed
feat: better scanning logic
1 parent fdae813 commit 6c6e0ab

File tree

7 files changed

+67
-41
lines changed

7 files changed

+67
-41
lines changed

dlgImport.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
from PySide6.QtWidgets import QDialog, QDialogButtonBox
3-
from PySide6.QtCore import Slot
43
from ui_dlgImport import Ui_Dialog
54

65
__all__ = ['dlgImport']

dlgScan.ui

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</sizepolicy>
7070
</property>
7171
<property name="currentIndex">
72-
<number>5</number>
72+
<number>7</number>
7373
</property>
7474
<item>
7575
<property name="text">
@@ -147,7 +147,7 @@
147147
<double>0.500000000000000</double>
148148
</property>
149149
<property name="value">
150-
<double>2.500000000000000</double>
150+
<double>1.500000000000000</double>
151151
</property>
152152
</widget>
153153
</item>
@@ -185,14 +185,31 @@
185185
</layout>
186186
</item>
187187
<item>
188-
<widget class="QCheckBox" name="chkBox_extendScan">
189-
<property name="toolTip">
190-
<string>扩大扫描范围,会扫描IPv6。建议在普通扫描结果较少或无结果时使用。</string>
191-
</property>
192-
<property name="text">
193-
<string>扩展扫描(实验性功能)</string>
194-
</property>
195-
</widget>
188+
<layout class="QHBoxLayout" name="extendScanLayout">
189+
<item>
190+
<widget class="QCheckBox" name="chkBox_extend4">
191+
<property name="toolTip">
192+
<string>扩大 IPv4 扫描范围。</string>
193+
</property>
194+
<property name="text">
195+
<string>扩展扫描 IPv4</string>
196+
</property>
197+
<property name="checked">
198+
<bool>true</bool>
199+
</property>
200+
</widget>
201+
</item>
202+
<item>
203+
<widget class="QCheckBox" name="chkBox_extend6">
204+
<property name="toolTip">
205+
<string>扩大扫描范围,增加 IPv6 支持。</string>
206+
</property>
207+
<property name="text">
208+
<string>扩展扫描 IPv6</string>
209+
</property>
210+
</widget>
211+
</item>
212+
</layout>
196213
</item>
197214
<item>
198215
<widget class="QDialogButtonBox" name="buttonBox">

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,13 @@ def on_btnWait_Scan_clicked(self):
250250
timeout = dlg.ui.spinBox_timeout.value()
251251
enableOptimization = dlg.ui.chkBox_optimize.isChecked()
252252
autoTest = dlg.ui.chkBox_autoTest.isChecked()
253-
extendScan = dlg.ui.chkBox_extendScan.isChecked()
253+
extend4 = dlg.ui.chkBox_extend4.isChecked()
254+
extend6 = dlg.ui.chkBox_extend6.isChecked()
254255

255256
self.__set_buttons_enabled(False)
256257
self.ui.ipList.clear()
257258
self.ui.statusbar.showMessage('开始扫描,请稍候...')
258-
thread = ScanThread(self, max_ips, num_workers, timeout, enableOptimization, extendScan)
259+
thread = ScanThread(self, max_ips, num_workers, timeout, enableOptimization, extend4, extend6)
259260
thread.finished.connect(self.__test_ips if autoTest else self.__scan_finished)
260261
thread.foundAvailable.connect(self.__got_scan_result)
261262
thread.start()

threads.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,52 +66,45 @@ def run(self):
6666

6767
class ScanThread(QThread):
6868
foundAvailable = Signal(str)
69-
available_suffixes = {90, 185}
7069

7170
# https://repo.or.cz/gscan_quic.git/blob/89e4b91eb3642b12f7665f7a9f4fa33c403fc318:/iprange_gws_b.txt
7271
net_default = IPv4Network('142.250.0.0/15')
7372
ipv4_extend = [
74-
IPv4Network('108.170.192.0/18'),
7573
IPv4Network('108.177.0.0/17'),
76-
IPv4Network('172.110.32.0/21'),
7774
IPv4Network('172.217.0.0/16'),
7875
IPv4Network('172.253.0.0/16'),
7976
IPv4Network('216.58.192.0/19'),
80-
IPv4Network('216.73.80.0/20'),
81-
IPv4Network('216.239.32.0/19')
77+
IPv4Network('72.14.192.0/18'),
78+
IPv4Network('74.125.0.0/16')
8279
]
8380

8481
# https://repo.or.cz/gscan_quic.git/blob/89e4b91eb3642b12f7665f7a9f4fa33c403fc318:/iprange_gws_6_a.txt
8582
ipv6_extend = [
83+
IPv6Network('2404:6800:4008:c15::0/112'),
8684
IPv6Network('2a00:1450:4001:802::0/112'),
87-
IPv6Network('2a00:1450:4001:803::0/112'),
88-
IPv6Network('2a00:1450:4001:809::0/112'),
89-
IPv6Network('2a00:1450:4001:811::0/112'),
90-
IPv6Network('2a00:1450:4001:827::0/112'),
91-
IPv6Network('2a00:1450:4001:828::0/112'),
92-
IPv6Network('2a00:1450:4001:829::0/112'),
93-
IPv6Network('2a00:1450:4001:830::0/112'),
94-
IPv6Network('2a00:1450:4001:831::0/112')
85+
IPv6Network('2a00:1450:4001:803::0/112')
9586
]
9687

9788
def __init__(self, parent, max_ips=5, num_workers=80, timeout=2.5,
98-
enableOptimization=True, extendScan=False):
89+
enableOptimization=True, extend4=False, extend6=False):
9990
super().__init__(parent)
10091

10192
self.max_ips = max_ips
10293
self.num_workers = num_workers
10394
self.timeout = timeout
10495

10596
self.networks = [
106-
[ip for ip in self.net_default if int(ip) & 0xff in self.available_suffixes]
97+
[ip for ip in self.net_default if int(ip) & 0xff == 90]
10798
if enableOptimization else list(self.net_default)
10899
]
109-
if extendScan:
100+
101+
if extend4:
110102
self.networks.extend(self.ipv4_extend)
103+
if extend6:
111104
self.networks.extend(self.ipv6_extend)
112105

113106
self.currentIndex = 0
114-
self.block_size = 15 if extendScan else max(15, self.num_workers // 4)
107+
self.block_size = max(50, num_workers // 2)
115108

116109
def __found_available(self, ip):
117110
if self.counter >= self.max_ips:
@@ -143,4 +136,5 @@ def run(self):
143136
self.pool.setMaxThreadCount(self.num_workers)
144137
self.counter = 0
145138
while self.counter < self.max_ips and self.__add_block():
146-
self.pool.waitForDone()
139+
self.pool.waitForDone()
140+
self.pool.waitForDone()

ui_MainWindow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
################################################################################
44
## Form generated from reading UI file 'MainWindow.ui'
55
##
6-
## Created by: Qt User Interface Compiler version 6.4.0
6+
## Created by: Qt User Interface Compiler version 6.5.2
77
##
88
## WARNING! All changes made in this file will be lost when recompiling UI file!
99
################################################################################

ui_dlgImport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
################################################################################
44
## Form generated from reading UI file 'dlgImport.ui'
55
##
6-
## Created by: Qt User Interface Compiler version 6.4.0
6+
## Created by: Qt User Interface Compiler version 6.5.2
77
##
88
## WARNING! All changes made in this file will be lost when recompiling UI file!
99
################################################################################

ui_dlgScan.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
################################################################################
44
## Form generated from reading UI file 'dlgScan.ui'
55
##
6-
## Created by: Qt User Interface Compiler version 6.4.0
6+
## Created by: Qt User Interface Compiler version 6.5.2
77
##
88
## WARNING! All changes made in this file will be lost when recompiling UI file!
99
################################################################################
@@ -95,7 +95,7 @@ def setupUi(self, Dialog):
9595
self.spinBox_timeout.setMinimum(1.000000000000000)
9696
self.spinBox_timeout.setMaximum(10.000000000000000)
9797
self.spinBox_timeout.setSingleStep(0.500000000000000)
98-
self.spinBox_timeout.setValue(2.500000000000000)
98+
self.spinBox_timeout.setValue(1.500000000000000)
9999

100100
self.horizontalLayout.addWidget(self.spinBox_timeout)
101101

@@ -124,10 +124,21 @@ def setupUi(self, Dialog):
124124

125125
self.verticalLayout.addLayout(self.chkBoxLayout)
126126

127-
self.chkBox_extendScan = QCheckBox(Dialog)
128-
self.chkBox_extendScan.setObjectName(u"chkBox_extendScan")
127+
self.extendScanLayout = QHBoxLayout()
128+
self.extendScanLayout.setObjectName(u"extendScanLayout")
129+
self.chkBox_extend4 = QCheckBox(Dialog)
130+
self.chkBox_extend4.setObjectName(u"chkBox_extend4")
131+
self.chkBox_extend4.setChecked(True)
129132

130-
self.verticalLayout.addWidget(self.chkBox_extendScan)
133+
self.extendScanLayout.addWidget(self.chkBox_extend4)
134+
135+
self.chkBox_extend6 = QCheckBox(Dialog)
136+
self.chkBox_extend6.setObjectName(u"chkBox_extend6")
137+
138+
self.extendScanLayout.addWidget(self.chkBox_extend6)
139+
140+
141+
self.verticalLayout.addLayout(self.extendScanLayout)
131142

132143
self.buttonBox = QDialogButtonBox(Dialog)
133144
self.buttonBox.setObjectName(u"buttonBox")
@@ -141,7 +152,7 @@ def setupUi(self, Dialog):
141152
self.buttonBox.accepted.connect(Dialog.accept)
142153
self.buttonBox.rejected.connect(Dialog.reject)
143154

144-
self.comboBox_threads.setCurrentIndex(5)
155+
self.comboBox_threads.setCurrentIndex(7)
145156

146157

147158
QMetaObject.connectSlotsByName(Dialog)
@@ -167,8 +178,12 @@ def retranslateUi(self, Dialog):
167178
self.chkBox_optimize.setText(QCoreApplication.translate("Dialog", u"\u542f\u7528\u626b\u63cf\u4f18\u5316", None))
168179
self.chkBox_autoTest.setText(QCoreApplication.translate("Dialog", u"\u5b8c\u6210\u540e\u81ea\u52a8\u6d4b\u901f", None))
169180
#if QT_CONFIG(tooltip)
170-
self.chkBox_extendScan.setToolTip(QCoreApplication.translate("Dialog", u"\u6269\u5927\u626b\u63cf\u8303\u56f4\uff0c\u4f1a\u626b\u63cfIPv6\u3002\u5efa\u8bae\u5728\u666e\u901a\u626b\u63cf\u7ed3\u679c\u8f83\u5c11\u6216\u65e0\u7ed3\u679c\u65f6\u4f7f\u7528\u3002", None))
181+
self.chkBox_extend4.setToolTip(QCoreApplication.translate("Dialog", u"\u6269\u5927 IPv4 \u626b\u63cf\u8303\u56f4\u3002", None))
182+
#endif // QT_CONFIG(tooltip)
183+
self.chkBox_extend4.setText(QCoreApplication.translate("Dialog", u"\u6269\u5c55\u626b\u63cf IPv4", None))
184+
#if QT_CONFIG(tooltip)
185+
self.chkBox_extend6.setToolTip(QCoreApplication.translate("Dialog", u"\u6269\u5927\u626b\u63cf\u8303\u56f4\uff0c\u589e\u52a0 IPv6 \u652f\u6301\u3002", None))
171186
#endif // QT_CONFIG(tooltip)
172-
self.chkBox_extendScan.setText(QCoreApplication.translate("Dialog", u"\u6269\u5c55\u626b\u63cf\uff08\u5b9e\u9a8c\u6027\u529f\u80fd\uff09", None))
187+
self.chkBox_extend6.setText(QCoreApplication.translate("Dialog", u"\u6269\u5c55\u626b\u63cf IPv6", None))
173188
# retranslateUi
174189

0 commit comments

Comments
 (0)