Skip to content

Commit 7d07675

Browse files
author
Vahid Farid
committed
Update script.js
1 parent 004dc71 commit 7d07675

File tree

1 file changed

+85
-14
lines changed

1 file changed

+85
-14
lines changed

script.js

+85-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var cfIPv4 = []
2-
var cfIPv4ToScan = []
1+
let cfIPv4 = []
2+
let cfIPv4ToScan = []
33
const noOfEachRange24 = 30
44
const client = new XMLHttpRequest();
55
client.open('GET', 'https://raw.githubusercontent.com/vfarid/cf-ip-scanner/main/ipv4.txt');
@@ -24,14 +24,62 @@ let ipRegex;
2424
let immediateStop = false;
2525
let progressBar = document.getElementById('progress-bar');
2626
let progress = 0;
27+
let portNo = 443;
28+
let protocol = "https";
2729
let language = localStorage.getItem('lang') || 'fa'
2830

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;
3133
document.getElementById('ip-regex').value = localStorage.getItem('ip-regex');
3234
document.getElementById('ip-include').value = localStorage.getItem('ip-include');
3335
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+
}
3583

3684
function setLang(lang) {
3785
if (lang == 'fa') {
@@ -67,6 +115,9 @@ document.getElementById('btn-fa').onclick = () => {
67115
document.getElementById('btn-cn').onclick = () => {
68116
setLang('cn')
69117
}
118+
document.getElementById('protocol').onchange = () => {
119+
setProtocol()
120+
}
70121

71122
function cancelScan() {
72123
immediateStop = true;
@@ -76,7 +127,11 @@ function cancelScan() {
76127
document.getElementById('ip-regex').disabled = false;
77128
document.getElementById('ip-include').disabled = false;
78129
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');
80135
}
81136

82137
let ips = [];
@@ -87,12 +142,16 @@ function startScan() {
87142
ipRegex = document.getElementById('ip-regex').value;
88143
ipInclude = document.getElementById('ip-include').value;
89144
ipExclude = document.getElementById('ip-exclude').value;
145+
portNo = document.getElementById('port-no').value;
146+
protocol = document.getElementById('protocol').value;
90147

91148
localStorage.setItem('max-ip', maxIP);
92149
localStorage.setItem('max-latency', maxLatency);
93150
localStorage.setItem('ip-regex', ipRegex);
94151
localStorage.setItem('ip-include', ipInclude);
95152
localStorage.setItem('ip-exclude', ipExclude);
153+
localStorage.setItem('port-no', portNo);
154+
localStorage.setItem('protocol', protocol);
96155

97156
testNo = 0;
98157
numberOfWorkingIPs = 0;
@@ -104,8 +163,12 @@ function startScan() {
104163
document.getElementById('ip-regex').disabled = true;
105164
document.getElementById('ip-include').disabled = true;
106165
document.getElementById('ip-exclude').disabled = true;
166+
document.getElementById('port-no').disabled = true;
167+
document.getElementById('protocol').disabled = true;
107168
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');
109172

110173
setTimeout(() => {
111174
let ips = processIPs()
@@ -144,21 +207,25 @@ function processIPs() {
144207
return ips
145208
}
146209

147-
148-
149210
async function testIPs(ipList) {
150211
for (const ip of ipList) {
151212
if (immediateStop) {
152213
break;
153214
}
154215
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+
157224
const startTime = performance.now();
158225
const controller = new AbortController();
159226
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;
162229
for (const ch of ['', '|', '/', '-', '\\']) {
163230
const timeoutId = setTimeout(() => {
164231
controller.abort();
@@ -227,7 +294,11 @@ async function testIPs(ipList) {
227294
document.getElementById('ip-regex').disabled = false;
228295
document.getElementById('ip-include').disabled = false;
229296
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');
231302

232303
if (immediateStop) {
233304
immediateStop = false;

0 commit comments

Comments
 (0)