-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.html
More file actions
390 lines (358 loc) · 13.4 KB
/
Copy pathsearch.html
File metadata and controls
390 lines (358 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IP Flag Checker | Lightweight</title>
<style>
* { box-sizing: border-box; }
body {
width: 90%;
max-width: 1100px;
margin: 2rem auto;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
background: #f4f6fa;
color: #1e293b;
line-height: 1.4;
}
#dxcontainer {
background: white;
border-radius: 2rem;
padding: 2rem;
box-shadow: 0 8px 20px rgba(0,0,0,0.05);
}
.tcenter { text-align: center; }
.svg-icon-question {
width: 4rem;
height: 4rem;
filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}
.svg-icon-question path { fill: #2c7a4d; }
.search-container {
max-width: 650px;
margin: 1.5rem auto;
}
.ip-search-form {
display: flex;
background: white;
border: 1px solid #e2e8f0;
border-radius: 60px;
overflow: hidden;
transition: 0.2s;
}
.ip-search-form:focus-within {
border-color: #2c7a4d;
box-shadow: 0 0 0 3px rgba(44,122,77,0.2);
}
.ip-search-form input {
flex: 1;
padding: 0.9rem 1.5rem;
font-size: 1rem;
border: none;
outline: none;
font-family: monospace;
}
.ip-search-form button {
background: #2c7a4d;
border: none;
padding: 0 1.8rem;
font-weight: 600;
color: white;
cursor: pointer;
font-size: 1rem;
transition: background 0.2s;
display: flex;
align-items: center;
gap: 0.5rem;
}
.ip-search-form button:hover { background: #1e5a3a; }
.result-card {
max-width: 650px;
margin: 1.5rem auto;
padding: 1.2rem 1.5rem;
border-radius: 2rem;
background: #f8fafc;
border-left: 6px solid transparent;
font-weight: 500;
}
.result-flagged { background: #fff1f0; border-left-color: #e53e3e; }
.result-clean { background: #e6f7ec; border-left-color: #2c7a4d; }
.result-loading { background: #f1f5f9; border-left-color: #fbbf24; }
.result-error { background: #fef2e8; border-left-color: #dd6b20; }
.badge {
display: inline-block;
background: rgba(0,0,0,0.05);
padding: 0.2rem 1rem;
border-radius: 40px;
font-size: 0.8rem;
}
.status-msg { font-size: 1.2rem; font-weight: 600; margin-top: 0.5rem; }
.stats {
font-size: 0.85rem;
color: #475569;
background: #f1f5f9;
padding: 0.3rem 1rem;
border-radius: 30px;
display: inline-block;
}
.loading-spinner {
display: inline-block;
width: 18px;
height: 18px;
border: 2px solid #cbd5e1;
border-top-color: #2c7a4d;
border-radius: 50%;
animation: spin 0.7s linear infinite;
margin-right: 0.5rem;
vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.footer-link {
display: inline-block;
margin-top: 1rem;
padding: 0.4rem 1.2rem;
background: #f1f5f9;
border-radius: 40px;
text-decoration: none;
color: #2c7a4d;
font-size: 0.9rem;
}
hr { margin: 2rem 0 1rem; border: none; border-top: 1px solid #e2e8f0; }
@media (max-width: 640px) {
body { width: 95%; margin: 1rem auto; }
#dxcontainer { padding: 1.2rem; }
}
</style>
</head>
<body>
<div id="dxcontainer">
<div class="tcenter">
<svg class="svg-icon-question" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.57 6.033H5.25C5.22 4.147 6.68 3.5 8.006 3.5c1.397 0 2.673.73 2.673 2.24 0 1.08-.635 1.594-1.244 2.057-.737.559-1.01.768-1.01 1.486v.355H7.117l-.007-.463c-.038-.927.495-1.498 1.168-1.987.59-.444.965-.736.965-1.371 0-.825-.628-1.168-1.314-1.168-.901 0-1.358.603-1.358 1.384zm1.251 6.443c-.584 0-1.009-.394-1.009-.927 0-.552.425-.94 1.01-.94.609 0 1.028.388 1.028.94 0 .533-.42.927-1.029.927z"/>
</svg>
<h2>🔍 IP Blocklist Scanner</h2>
<p>Check if an IP is flagged in our curated blocklist (no API calls, static files only).</p>
</div>
<div class="search-container">
<form id="ipCheckForm" class="ip-search-form">
<input type="text" id="ipInput" placeholder="IPv4 address: 192.168.1.1 or 203.0.113.0/24" autocomplete="off">
<button type="submit">
<svg width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M10.442 10.442a1 1 0 0 1 1.415 0l3.85 3.85a1 1 0 0 1-1.414 1.415l-3.85-3.85a1 1 0 0 1 0-1.415z"/>
<path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zM13 6.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0z"/>
</svg>
CHECK
</button>
</form>
</div>
<div id="resultArea" class="result-card result-loading" style="display: none;"></div>
<div class="tcenter">
<span id="dataStatus" class="stats">⚙️ Loading blocklist from GitHub (raw files)…</span>
</div>
<div class="tcenter">
<hr>
<a href="https://github.com/cssmfc/block/discussions/categories/contact" target="_blank" rel="noopener" class="footer-link">📢 Report false positive / Contact</a>
</div>
</div>
<script>
// ========= CONFIGURATION =========
// 👇 EDIT THIS LIST: add your .txt file(s) from the 'feed-ban-ip' folder
const TXT_FILES = [
'feed-ban-ip/combined.txt' // <-- recommended: one file with all IPs + CIDRs
// 'feed-ban-ip/another-list.txt',
];
const GITHUB_RAW_BASE = 'https://raw.githubusercontent.com/cssmfc/block/main/';
// =================================
let blocklistIPs = new Set(); // exact IPv4 matches
let cidrBlocks = []; // { networkInt, maskInt, cidrString }
let isDataReady = false;
let isLoading = false;
// --- helpers ---
function isValidIPv4(ip) {
const regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
return regex.test(ip);
}
function ipToInt(ip) {
const parts = ip.split('.');
return ((parseInt(parts[0]) << 24) >>> 0) +
((parseInt(parts[1]) << 16) >>> 0) +
((parseInt(parts[2]) << 8) >>> 0) +
parseInt(parts[3]);
}
function parseCIDR(cidr) {
const [ip, prefixBits] = cidr.split('/');
const prefix = parseInt(prefixBits, 10);
const ipInt = ipToInt(ip);
const maskInt = (0xFFFFFFFF << (32 - prefix)) >>> 0;
const networkInt = (ipInt & maskInt) >>> 0;
return { networkInt, maskInt, cidrString: cidr, prefix };
}
function ipMatchesCIDR(ipInt, cidrObj) {
return (ipInt & cidrObj.maskInt) >>> 0 === cidrObj.networkInt;
}
function isIpFlagged(ip) {
if (!isDataReady) return false;
if (blocklistIPs.has(ip)) return true;
const ipInt = ipToInt(ip);
for (const cidr of cidrBlocks) {
if (ipMatchesCIDR(ipInt, cidr)) return true;
}
return false;
}
// parse lines from a .txt file content
function parseBlocklist(content) {
const lines = content.split(/\r?\n/);
const ips = new Set();
const cidrs = [];
for (let line of lines) {
line = line.trim();
if (line === '' || line.startsWith('#')) continue;
if (line.includes('/')) {
if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}$/.test(line)) {
cidrs.push(parseCIDR(line));
}
} else if (isValidIPv4(line)) {
ips.add(line);
}
}
return { ips, cidrs };
}
// fetch one or more .txt files, merge them
async function loadBlocklist() {
if (isLoading) return;
isLoading = true;
updateStatus('⟳ Fetching blocklist files (static, no API)...', 'loading');
try {
if (TXT_FILES.length === 0) {
throw new Error('No TXT_FILES defined. Edit the script and add your file(s).');
}
const fetchPromises = TXT_FILES.map(async (relativePath) => {
const url = GITHUB_RAW_BASE + relativePath;
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed to fetch ${relativePath} (HTTP ${res.status})`);
const text = await res.text();
return parseBlocklist(text);
});
const results = await Promise.all(fetchPromises);
// reset data
blocklistIPs.clear();
cidrBlocks = [];
for (const parsed of results) {
for (const ip of parsed.ips) blocklistIPs.add(ip);
for (const cidr of parsed.cidrs) {
// avoid duplicates based on cidrString
if (!cidrBlocks.some(ex => ex.cidrString === cidr.cidrString)) {
cidrBlocks.push(cidr);
}
}
}
isDataReady = true;
updateStatus(`✅ Ready — ${blocklistIPs.size} exact IPs + ${cidrBlocks.length} CIDR ranges loaded from ${TXT_FILES.length} file(s).`, 'ready');
} catch (err) {
console.error(err);
updateStatus(`⚠️ ${err.message || 'Could not load blocklist. Check file paths and CORS.'}`, 'error');
isDataReady = false;
} finally {
isLoading = false;
}
}
function updateStatus(msg, type) {
const el = document.getElementById('dataStatus');
if (el) {
el.innerHTML = msg;
el.style.color = type === 'error' ? '#c2410c' : (type === 'ready' ? '#2c7a4d' : '#475569');
}
}
function showResult(ip, flagged, errorMsg = null) {
const resultDiv = document.getElementById('resultArea');
if (!resultDiv) return;
resultDiv.style.display = 'block';
if (errorMsg) {
resultDiv.className = 'result-card result-error';
resultDiv.innerHTML = `<div class="badge">⚠️ ERROR</div>
<div class="status-msg">${escapeHtml(errorMsg)}</div>`;
return;
}
if (flagged) {
resultDiv.className = 'result-card result-flagged';
resultDiv.innerHTML = `<div class="badge">🚨 FLAGGED</div>
<div class="status-msg">IP <strong>${escapeHtml(ip)}</strong> is in the blocklist.</div>
<div style="margin-top:8px;">This address is considered malicious or suspicious.</div>`;
} else {
resultDiv.className = 'result-card result-clean';
resultDiv.innerHTML = `<div class="badge">✅ CLEAN</div>
<div class="status-msg">IP <strong>${escapeHtml(ip)}</strong> was NOT found.</div>
<div style="margin-top:8px;">No active flag for this address.</div>`;
}
}
function escapeHtml(str) {
if (!str) return '';
return str.replace(/[&<>]/g, function(m) {
if (m === '&') return '&';
if (m === '<') return '<';
if (m === '>') return '>';
return m;
});
}
// Handle search
async function onCheckIP(e) {
e.preventDefault();
const input = document.getElementById('ipInput');
let raw = input.value.trim();
const resultDiv = document.getElementById('resultArea');
if (!raw) {
showResult('', false, 'Please enter an IP address (e.g., 1.2.3.4)');
return;
}
// If user typed a CIDR, warn that we check single IPs only (but we can still check if the IP part exists)
let ipToCheck = raw;
if (raw.includes('/')) {
if (!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}$/.test(raw)) {
showResult(raw, false, 'Invalid CIDR format. Use a single IPv4 address like 8.8.8.8');
return;
} else {
showResult(raw, false, 'The tool checks individual IP addresses. Please enter only the IP (e.g., 1.2.3.4)');
return;
}
}
if (!isValidIPv4(ipToCheck)) {
showResult(raw, false, 'Invalid IPv4 address. Format: 192.168.0.1');
return;
}
// show loading inside result
resultDiv.style.display = 'block';
resultDiv.className = 'result-card result-loading';
resultDiv.innerHTML = `<div class="loading-spinner"></div> Checking against blocklist...`;
// If data not ready, try to load it now (but only if not already loading)
if (!isDataReady && !isLoading) {
updateStatus('⟳ Loading blocklist, please wait...', 'loading');
await loadBlocklist();
// after load, re-check
if (!isDataReady) {
showResult(ipToCheck, false, 'Blocklist not available. Check file paths or network.');
return;
}
} else if (!isDataReady && isLoading) {
// wait up to 3 seconds for ongoing load
let waited = 0;
while (!isDataReady && isLoading && waited < 3000) {
await new Promise(r => setTimeout(r, 200));
waited += 200;
}
if (!isDataReady) {
showResult(ipToCheck, false, 'Blocklist still loading. Please try again in a moment.');
return;
}
}
const flagged = isIpFlagged(ipToCheck);
showResult(ipToCheck, flagged);
}
// Auto-load when page loads
window.addEventListener('DOMContentLoaded', () => {
loadBlocklist();
const form = document.getElementById('ipCheckForm');
if (form) form.addEventListener('submit', onCheckIP);
});
</script>
</body>
</html>