1
- var cfIPv4 = [ ]
2
- var cfIPv4ToScan = [ ]
1
+ let cfIPv4 = [ ]
2
+ let cfIPv4ToScan = [ ]
3
3
const noOfEachRange24 = 30
4
4
const client = new XMLHttpRequest ( ) ;
5
5
client . open ( 'GET' , 'https://raw.githubusercontent.com/vfarid/cf-ip-scanner/main/ipv4.txt' ) ;
@@ -24,14 +24,62 @@ let ipRegex;
24
24
let immediateStop = false ;
25
25
let progressBar = document . getElementById ( 'progress-bar' ) ;
26
26
let progress = 0 ;
27
+ let portNo = 443 ;
28
+ let protocol = "https" ;
27
29
let language = localStorage . getItem ( 'lang' ) || 'fa'
28
30
29
- document . getElementById ( 'max-ip' ) . value = localStorage . getItem ( 'max-ip' ) || 20 ;
30
- document . getElementById ( 'max-latency' ) . value = localStorage . getItem ( 'max-latency' ) || 400 ;
31
+ document . getElementById ( 'max-ip' ) . value = localStorage . getItem ( 'max-ip' ) || 10 ;
32
+ document . getElementById ( 'max-latency' ) . value = localStorage . getItem ( 'max-latency' ) || 600 ;
31
33
document . getElementById ( 'ip-regex' ) . value = localStorage . getItem ( 'ip-regex' ) ;
32
34
document . getElementById ( 'ip-include' ) . value = localStorage . getItem ( 'ip-include' ) ;
33
35
document . getElementById ( 'ip-exclude' ) . value = localStorage . getItem ( 'ip-exclude' ) ;
34
- setLang ( language )
36
+ document . getElementById ( 'protocol' ) . value = localStorage . getItem ( 'protocol' ) || "https" ;
37
+ setLang ( language ) ;
38
+ setProtocol ( ) ;
39
+
40
+ function setProtocol ( ) {
41
+ const ports = {
42
+ http : [ "80" , "8080" , "2052" , "2082" , "2086" , "2095" ] ,
43
+ https : [ "443" , "8443" , "2053" , "2083" , "2087" , "2096" ] ,
44
+ } ;
45
+
46
+ portNo = document . getElementById ( 'port-no' ) . value || localStorage . getItem ( 'port-no' ) ;
47
+ console . log ( portNo )
48
+ document . getElementById ( 'port-no' ) . innerHTML = "" ;
49
+ if ( document . getElementById ( 'protocol' ) . value == 'http' ) {
50
+ for ( let port of ports . http ) {
51
+ document . getElementById ( 'port-no' ) . options . add ( new Option ( port ) )
52
+ }
53
+ if ( ports . http . indexOf ( portNo ) < 0 && ports . https . indexOf ( portNo ) >= 0 ) {
54
+ portNo = ports . http [ ports . https . indexOf ( portNo ) ] ;
55
+ }
56
+ if ( ! portNo ) {
57
+ portNo = ports . http [ 0 ]
58
+ }
59
+ } else {
60
+ for ( let port of ports . https ) {
61
+ document . getElementById ( 'port-no' ) . options . add ( new Option ( port ) )
62
+ }
63
+ if ( ports . https . indexOf ( portNo ) < 0 && ports . http . indexOf ( portNo ) >= 0 ) {
64
+ portNo = ports . https [ ports . http . indexOf ( portNo ) ] ;
65
+ }
66
+ if ( ! portNo ) {
67
+ portNo = ports . https [ 0 ]
68
+ }
69
+ }
70
+ setTimeout ( ( ) => { document . getElementById ( 'port-no' ) . value = portNo } , 1 ) ;
71
+ }
72
+
73
+ function resetDefaults ( ) {
74
+ localStorage . removeItem ( 'max-ip' ) ;
75
+ localStorage . removeItem ( 'max-latency' ) ;
76
+ localStorage . removeItem ( 'ip-regex' ) ;
77
+ localStorage . removeItem ( 'ip-include' ) ;
78
+ localStorage . removeItem ( 'ip-exclude' ) ;
79
+ localStorage . removeItem ( 'port-no' ) ;
80
+ localStorage . removeItem ( 'protocol' ) ;
81
+ document . location = document . location ;
82
+ }
35
83
36
84
function setLang ( lang ) {
37
85
if ( lang == 'fa' ) {
@@ -67,6 +115,9 @@ document.getElementById('btn-fa').onclick = () => {
67
115
document . getElementById ( 'btn-cn' ) . onclick = ( ) => {
68
116
setLang ( 'cn' )
69
117
}
118
+ document . getElementById ( 'protocol' ) . onchange = ( ) => {
119
+ setProtocol ( )
120
+ }
70
121
71
122
function cancelScan ( ) {
72
123
immediateStop = true ;
@@ -76,7 +127,11 @@ function cancelScan() {
76
127
document . getElementById ( 'ip-regex' ) . disabled = false ;
77
128
document . getElementById ( 'ip-include' ) . disabled = false ;
78
129
document . getElementById ( 'ip-exclude' ) . disabled = false ;
79
- document . getElementById ( 'btn-cancel' ) . disabled = true ;
130
+ document . getElementById ( 'port-no' ) . disabled = false ;
131
+ document . getElementById ( 'protocol' ) . disabled = false ;
132
+ document . getElementById ( 'btn-cancel' ) . classList . add ( 'd-none' ) ;
133
+ document . getElementById ( 'btn-start' ) . classList . remove ( 'd-none' ) ;
134
+ document . getElementById ( 'btn-reset' ) . classList . remove ( 'd-none' ) ;
80
135
}
81
136
82
137
let ips = [ ] ;
@@ -87,12 +142,16 @@ function startScan() {
87
142
ipRegex = document . getElementById ( 'ip-regex' ) . value ;
88
143
ipInclude = document . getElementById ( 'ip-include' ) . value ;
89
144
ipExclude = document . getElementById ( 'ip-exclude' ) . value ;
145
+ portNo = document . getElementById ( 'port-no' ) . value ;
146
+ protocol = document . getElementById ( 'protocol' ) . value ;
90
147
91
148
localStorage . setItem ( 'max-ip' , maxIP ) ;
92
149
localStorage . setItem ( 'max-latency' , maxLatency ) ;
93
150
localStorage . setItem ( 'ip-regex' , ipRegex ) ;
94
151
localStorage . setItem ( 'ip-include' , ipInclude ) ;
95
152
localStorage . setItem ( 'ip-exclude' , ipExclude ) ;
153
+ localStorage . setItem ( 'port-no' , portNo ) ;
154
+ localStorage . setItem ( 'protocol' , protocol ) ;
96
155
97
156
testNo = 0 ;
98
157
numberOfWorkingIPs = 0 ;
@@ -104,8 +163,12 @@ function startScan() {
104
163
document . getElementById ( 'ip-regex' ) . disabled = true ;
105
164
document . getElementById ( 'ip-include' ) . disabled = true ;
106
165
document . getElementById ( 'ip-exclude' ) . disabled = true ;
166
+ document . getElementById ( 'port-no' ) . disabled = true ;
167
+ document . getElementById ( 'protocol' ) . disabled = true ;
107
168
document . getElementById ( 'test-no' ) . innerText = '' ;
108
- document . getElementById ( 'btn-cancel' ) . disabled = false ;
169
+ document . getElementById ( 'btn-cancel' ) . classList . remove ( 'd-none' ) ;
170
+ document . getElementById ( 'btn-start' ) . classList . add ( 'd-none' ) ;
171
+ document . getElementById ( 'btn-reset' ) . classList . add ( 'd-none' ) ;
109
172
110
173
setTimeout ( ( ) => {
111
174
let ips = processIPs ( )
@@ -144,21 +207,25 @@ function processIPs() {
144
207
return ips
145
208
}
146
209
147
-
148
-
149
210
async function testIPs ( ipList ) {
150
211
for ( const ip of ipList ) {
151
212
if ( immediateStop ) {
152
213
break ;
153
214
}
154
215
testNo ++ ;
155
- var testResult = 0 ;
156
- const url = `https://${ ip } :2096/__down` ;
216
+ let testResult = 0 ;
217
+ let url = null ;
218
+ if ( protocol == 'https' ) {
219
+ url = `https://${ ip } :${ portNo } /__down` ;
220
+ } else {
221
+ url = `http://${ ip } :${ portNo } /cdn-cgi/trace` ;
222
+ }
223
+
157
224
const startTime = performance . now ( ) ;
158
225
const controller = new AbortController ( ) ;
159
226
const multiply = maxLatency <= 500 ? 1.5 : ( maxLatency <= 1000 ? 1.2 : 1 ) ;
160
- var timeout = 1.5 * multiply * maxLatency ;
161
- var chNo = 0 ;
227
+ let timeout = 1.5 * multiply * maxLatency ;
228
+ let chNo = 0 ;
162
229
for ( const ch of [ '' , '|' , '/' , '-' , '\\' ] ) {
163
230
const timeoutId = setTimeout ( ( ) => {
164
231
controller . abort ( ) ;
@@ -227,7 +294,11 @@ async function testIPs(ipList) {
227
294
document . getElementById ( 'ip-regex' ) . disabled = false ;
228
295
document . getElementById ( 'ip-include' ) . disabled = false ;
229
296
document . getElementById ( 'ip-exclude' ) . disabled = false ;
230
- document . getElementById ( 'btn-cancel' ) . disabled = true ;
297
+ document . getElementById ( 'port-no' ) . disabled = false ;
298
+ document . getElementById ( 'protocol' ) . disabled = false ;
299
+ document . getElementById ( 'btn-cancel' ) . classList . add ( 'd-none' ) ;
300
+ document . getElementById ( 'btn-start' ) . classList . remove ( 'd-none' ) ;
301
+ document . getElementById ( 'btn-reset' ) . classList . remove ( 'd-none' ) ;
231
302
232
303
if ( immediateStop ) {
233
304
immediateStop = false ;
0 commit comments