更新完善功能
This commit is contained in:
1 parent
4e6d6e5307
commit
e08a87a4c2
8 files changed
+330
-95
No files matched your search
@@ -409,6 +409,8 @@ a.nav-btn[data-note]:hover::after { opacity: 1; transform: translateX(-50%) tran
|
||||
.fieldset-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
|
||||
.fieldset-card > .fs-title { font-weight: 700; font-size: 16px; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
|
||||
/* 跨整行的设置卡片(内容较多的底部大卡) */
|
||||
.fieldset-card.col-span-2 { grid-column: 1 / -1; }
|
||||
|
||||
/* 后台导航内容管理 */
|
||||
.m-block { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; overflow: hidden; }
|
||||
|
||||
+95
-19
@@ -1,9 +1,10 @@
|
||||
/* ip.js —— IP 地址处理
|
||||
* 提取输入文本中全部 IPv4 → 按 /24 段聚合输出(文本 / 高亮预览):
|
||||
* IP段 发现数量(段内去重IP数) IP段性质
|
||||
* 1.2.3.0/24 8 公网
|
||||
* 1.2.3.4
|
||||
* IP段 发现数量(段内去重IP数) IP段性质 出现次数
|
||||
* 1.2.3.0/24 8 公网 56
|
||||
* 1.2.3.4 出现次数
|
||||
*
|
||||
* 段按出现次数(段内全部 IP 原文出现次数之和)从高到低排列;
|
||||
* 「重点匹配 IP」:填写的 IP 命中后,其所在 /24 段优先置顶、对应 IP 红色标出。
|
||||
* CDN 段库由服务端通过 #ipCdnRaw 隐藏文本框注入,可在后台维护。
|
||||
*/
|
||||
@@ -106,11 +107,15 @@
|
||||
|
||||
var TYPE_ZH = { priv: '内网', cdn: 'CDN', pub: '公网' };
|
||||
|
||||
/* 返回 { segs:[{line, hit, ips:[{ip,hit}]}], segTotals, totalIps, totalSeg, hitSeg, hitIps, rangeCount } */
|
||||
/* 返回 { segs:[{line, hit, count, ips:[...], details:[ip]}], totalCount, totalIps, totalSeg, hitSeg, hitIps, rangeCount, counts } */
|
||||
function analyze(text, cdnRaw, focusSet) {
|
||||
var all = extractIps(text);
|
||||
if (!all.length) return null;
|
||||
var ranges = parseCdnText(cdnRaw);
|
||||
var counts = {};
|
||||
for (var ci = 0; ci < all.length; ci++) {
|
||||
counts[all[ci]] = (counts[all[ci]] || 0) + 1;
|
||||
}
|
||||
|
||||
var segMap = {}, segOrder = [];
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
@@ -141,18 +146,26 @@
|
||||
}
|
||||
|
||||
var segs = segOrder.map(function (k) { return segMap[k]; });
|
||||
segs.forEach(function (s) { s.label = segLabel(s); });
|
||||
// 命中重点 IP 的段排前,组内段号升序
|
||||
var focusSegs = [], otherSegs = [];
|
||||
segs.forEach(function (s) {
|
||||
s.label = segLabel(s);
|
||||
// 段访问次数 = 段内全部具体 IP 在原文出现次数之和
|
||||
s.count = 0;
|
||||
s.ips.forEach(function (ip) { s.count += counts[ip] || 0; });
|
||||
});
|
||||
// 命中重点 IP 的段置顶;其余段按出现次数降序(同次数按段号升序)
|
||||
segs.forEach(function (s) {
|
||||
s.hit = s.ips.some(function (ip) { return focusSet[ip]; });
|
||||
(s.hit ? focusSegs : otherSegs).push(s);
|
||||
});
|
||||
segs = focusSegs.concat(otherSegs);
|
||||
segs.sort(function (a, b) {
|
||||
if (a.hit !== b.hit) return a.hit ? -1 : 1;
|
||||
if (a.count !== b.count) return b.count - a.count;
|
||||
return keyLess(a.key, b.key);
|
||||
});
|
||||
|
||||
var totalIps = 0, hitIps = 0, hitSeg = 0;
|
||||
var totalIps = 0, hitIps = 0, hitSeg = 0, totalCount = 0;
|
||||
segs.forEach(function (s) {
|
||||
totalIps += s.ips.length;
|
||||
totalCount += s.count;
|
||||
if (s.hit) hitSeg++;
|
||||
s.ips.sort(ipLess);
|
||||
var h = [], o = [];
|
||||
@@ -161,7 +174,7 @@
|
||||
else o.push(ip);
|
||||
});
|
||||
s.details = h.concat(o);
|
||||
s.line = s.key + '.0/24\t' + s.ips.length + '\t' + s.label;
|
||||
s.line = s.key + '.0/24\t' + s.ips.length + '\t' + s.label + '\t' + s.count;
|
||||
});
|
||||
|
||||
var cntSeg = { priv: 0, cdn: 0, pub: 0 };
|
||||
@@ -174,12 +187,14 @@
|
||||
|
||||
return {
|
||||
segs: segs,
|
||||
totalCount: totalCount,
|
||||
totalIps: totalIps,
|
||||
totalSeg: segs.length,
|
||||
hitSeg: hitSeg,
|
||||
hitIps: hitIps,
|
||||
cntSeg: cntSeg,
|
||||
rangeCount: ranges.length
|
||||
rangeCount: ranges.length,
|
||||
counts: counts
|
||||
};
|
||||
}
|
||||
|
||||
@@ -188,22 +203,24 @@
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
function plainText(data) {
|
||||
var lines = ['IP段\t发现数量\tIP段性质'];
|
||||
var lines = ['IP段 发现数量 IP段性质 出现次数'];
|
||||
data.segs.forEach(function (s) {
|
||||
lines.push(s.line);
|
||||
s.details.forEach(function (ip) { lines.push('\t' + ip); });
|
||||
s.details.forEach(function (ip) { lines.push(ip + ' ' + (data.counts[ip] || 1)); });
|
||||
lines.push('');
|
||||
});
|
||||
return lines.join('\n');
|
||||
}
|
||||
function previewHtml(data) {
|
||||
var parts = [];
|
||||
parts.push(esc('IP段\t发现数量\tIP段性质').replace(/\t/g, ' '));
|
||||
parts.push(esc('IP段 发现数量 IP段性质 出现次数').replace(/\t/g, ' '));
|
||||
data.segs.forEach(function (s) {
|
||||
var lineTxt = s.line.replace(/\t/g, ' ');
|
||||
parts.push(s.hit ? '<span class="ip-seg-hit">★ ' + esc(lineTxt) + '</span>' : esc(lineTxt));
|
||||
s.details.forEach(function (ip) {
|
||||
parts.push(focusCur[ip] ? '<span class="ip-hit">' + esc(ip) + '</span>' : esc(ip));
|
||||
var cnt = data.counts[ip] || 1;
|
||||
var row = esc(ip) + ' ' + cnt;
|
||||
parts.push(focusCur[ip] ? '<span class="ip-hit">' + row + '</span>' : row);
|
||||
});
|
||||
parts.push('');
|
||||
});
|
||||
@@ -234,10 +251,10 @@
|
||||
var d = lastData;
|
||||
$('ipPreview').innerHTML = previewHtml(d);
|
||||
var st = d.cntSeg;
|
||||
var note = '共提取去重 IP ' + d.totalIps + ' 个,涉及 ' + d.totalSeg + ' 个 /24 段(内网 ' +
|
||||
st.priv + ' 段 / CDN ' + st.cdn + ' 段 / 公网 ' + st.pub + ' 段)。';
|
||||
var note = 'IP 共出现 ' + d.totalCount + ' 次,去重 IP ' + d.totalIps + ' 个,涉及 ' + d.totalSeg + ' 个 /24 段(内网 ' +
|
||||
st.priv + ' 段 / CDN ' + st.cdn + ' 段 / 公网 ' + st.pub + ' 段),按段出现次数降序排列。';
|
||||
if (Object.keys(parseFocus($('ipFocus').value)).length === 0) {
|
||||
note += ' 未填写重点 IP,按原顺序输出。';
|
||||
note += ' 未填写重点 IP。';
|
||||
} else if (d.hitIps === 0) {
|
||||
note += ' 填写的重点 IP 均未在输入内容中命中。';
|
||||
} else {
|
||||
@@ -272,16 +289,75 @@
|
||||
}
|
||||
function clearAll() {
|
||||
$('ipInput').value = '';
|
||||
$('ipFile').value = '';
|
||||
$('ipFocus').value = '';
|
||||
$('ipMsg').innerHTML = '';
|
||||
$('ipResult').hidden = true;
|
||||
$('ipInput').focus();
|
||||
}
|
||||
|
||||
/* ---------- 上传文本文件识别 ---------- */
|
||||
var FILE_MAX = 20 * 1024 * 1024; // ≤ 20MB
|
||||
var FILE_EXTS = ['.txt', '.json', '.log', '.md', '.csv', '.conf', '.ini'];
|
||||
var fileInput = $('ipFile');
|
||||
if (fileInput) {
|
||||
fileInput.addEventListener('change', function () {
|
||||
var f = fileInput.files && fileInput.files[0];
|
||||
var msg = $('ipMsg');
|
||||
msg.innerHTML = '';
|
||||
if (!f) return;
|
||||
var name = (f.name || '').toLowerCase();
|
||||
var okExt = false;
|
||||
for (var ei = 0; ei < FILE_EXTS.length; ei++) {
|
||||
if (name.slice(-FILE_EXTS[ei].length) === FILE_EXTS[ei]) { okExt = true; break; }
|
||||
}
|
||||
if (!okExt) {
|
||||
msg.innerHTML = '<div class="err-msg">不支持的文件格式。请上传 txt / json / log / md / csv / conf / ini 文本文件。</div>';
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
if (f.size > FILE_MAX) {
|
||||
msg.innerHTML = '<div class="err-msg">文件超过 20MB 限制,请拆分后再分析。</div>';
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
var rd = new FileReader();
|
||||
rd.onload = function () {
|
||||
$('ipInput').value = String(rd.result || '');
|
||||
msg.innerHTML = '<div class="ok-msg">已读取「' + esc(f.name) + '」(' + (f.size / 1024).toFixed(1) + ' KB),正在分析…</div>';
|
||||
run();
|
||||
};
|
||||
rd.onerror = function () {
|
||||
msg.innerHTML = '<div class="err-msg">文件读取失败,请重试或改用文本粘贴。</div>';
|
||||
};
|
||||
rd.readAsText(f, 'UTF-8');
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 导出 TXT ---------- */
|
||||
function stamp() {
|
||||
var d = new Date(), p = function (n) { return (n < 10 ? '0' : '') + n; };
|
||||
return '' + d.getFullYear() + p(d.getMonth() + 1) + p(d.getDate()) + '_' + p(d.getHours()) + p(d.getMinutes()) + p(d.getSeconds());
|
||||
}
|
||||
function exportTxt() {
|
||||
if (!lastData) return;
|
||||
var text = plainText(lastData);
|
||||
var blob = new Blob(['\ufeff' + text], { type: 'text/plain;charset=utf-8' }); // BOM 便于记事本识别 UTF-8
|
||||
var url = URL.createObjectURL(blob);
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'ip_result_' + stamp() + '.txt';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
setTimeout(function () { URL.revokeObjectURL(url); }, 1500);
|
||||
}
|
||||
|
||||
$('ipBtn').addEventListener('click', run);
|
||||
$('ipCopy').addEventListener('click', function () {
|
||||
if (lastData) copyText(plainText(lastData));
|
||||
});
|
||||
$('ipExport').addEventListener('click', exportTxt);
|
||||
$('ipClear').addEventListener('click', clearAll);
|
||||
$('ipInput').addEventListener('keydown', function (ev) {
|
||||
if (ev.key === 'Enter' && (ev.ctrlKey || ev.metaKey)) run();
|
||||
|
||||
Reference in new issue
Block a user