From 2e7901f271c1ecbd95a32520e9375ad9ea36597d Mon Sep 17 00:00:00 2001 From: RaidandFade Date: Fri, 2 Feb 2024 01:58:33 +0000 Subject: [PATCH] mac address --- index.js | 6 +- mainpage.js => mainpage.html | 103 +++++++++++++++++++++++++++++++++++ webpack.config.js | 19 +++++++ 3 files changed, 125 insertions(+), 3 deletions(-) rename mainpage.js => mainpage.html (88%) create mode 100644 webpack.config.js diff --git a/index.js b/index.js index a7ba872..41b6025 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const Router = require('./router') -const MAINPAGE = require('./mainpage.js') +const MAINPAGE = require('./mainpage.html') addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) @@ -32,7 +32,7 @@ async function handleRequest(request) { const r = new Router() r.get('/', mainpage_html) - swjs = ` + let swjs = ` self.addEventListener("message", function(e) { if(e.data=="clear"){ caches.keys().then((a)=>{for(var b of a)caches.delete(b);}) @@ -45,7 +45,7 @@ async function handleRequest(request) { self.addEventListener("fetch", function(t) { if(this.devel == null) this.devel=false; const cache_prefix = "ip-tools-cache"; - const cache_version = "v1.0.2"; + const cache_version = "v1.0.3"; const cache_name = cache_prefix + "-" + cache_version; t.respondWith(caches.open(cache_name).then(function(cache){return cache.match(t.request).then(function(e) { diff --git a/mainpage.js b/mainpage.html similarity index 88% rename from mainpage.js rename to mainpage.html index c128412..7cf7452 100644 --- a/mainpage.js +++ b/mainpage.html @@ -70,6 +70,7 @@ "ipcidr":calccidr, "rdns":calcrdns, "ntoa":calcnum, + "mac":calcmac, "subs":calcsubnetlist, "subtbl":calcsubnettable, "ip2cidr":calcrange, @@ -250,6 +251,73 @@ $("#inputrdns").toggleClass("is-valid",valid) } +function calcmac(el){ + var val = getInputVal("#inputmac") + + var valid = /^([0-9a-fA-F]{2}[:\\-\\.]?){2,5}([0-9a-fA-F]{0,2})$/.test(val) + $("#inputmac").toggleClass("is-invalid",!valid) + $("#inputmac").toggleClass("is-valid",valid) + if(valid) + saveInputVal("#inputmac",val) + else + return + + fetch("https://maclookup.func.xny.onl/get/"+val).then((res)=>res.json()).then((res)=>{ + console.log(res) + var resbox = document.getElementById("res") + $("#mac-out1").val("") + $("#mac-out2").val("") + $("#mac-out3").val("") + $("#mac-out4").val("") + $("#mac-orgname").html("") + $("#maclist-out").html("") + + if(res['type']=="oui" || res['type']=="cid"){ + if(res['scope']=="global" || (res['scope']=="local" && res['type']=="cid")){ + if(res[res['type']]){ + var block_start = res[res['type']]['block'] + "0".repeat(12-res[res['type']]['block'].length) + var block_end = res[res['type']]['block'] + "f".repeat(12-res[res['type']]['block'].length) + + block_start = block_start.match(/.{2}/g).join(":").toUpperCase() + block_end = block_end.match(/.{2}/g).join(":").toUpperCase() + + $("#mac-out1").val(block_start + " - " + block_end) + $("#mac-out2").val(res['type']+" "+res[res['type']]['assignment']+" | "+res['usage']) + $("#mac-out3").val(res[res['type']]['org']['name']) + $("#mac-orgname").html(res[res['type']]['org']['name']) + fetch("https://maclookup.func.xny.onl/org/"+res[res['type']]['org']['id']).then((res)=>res.json()).then((res)=>{ + console.log(res) + let outhtml = "" + for(var block of res['blocks']){ + var block_start = block['block'] + "0".repeat(12-block['block'].length) + var block_end = block['block'] + "f".repeat(12-block['block'].length) + + block_start = block_start.match(/.{2}/g).join(":").toUpperCase() + block_end = block_end.match(/.{2}/g).join(":").toUpperCase() + + outhtml += '' + } + $("#maclist-out").html(outhtml) + }) + $("#mac-out4").val(res[res['type']]['org']['address']) + + + }else{ + $("#mac-out1").val("Unassigned") + $("#mac-out2").val(res['type'] + " "+ res['scope'] +" | "+res['usage']) + } + }else{ + $("#mac-out2").val(res['scope']+" | "+res['usage']) + $("#mac-out3").val(res['type']) + } + }else{ + $("#mac-out1").val("Private") + $("#mac-out2").val("Local " + res['usage']) + } + }) + +} + function calcnum(el){ var val = getInputVal("#inputnum") //$("#inputnum").val().trim() @@ -897,6 +965,9 @@ + @@ -964,6 +1035,38 @@ +
+
+
+
+ Mac Address +
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..228804f --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,19 @@ +var path = require("path") +// import path from "path"; +// import { fileURLToPath } from "url"; +// const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +module.exports = { + entry: './index.js', + experiments: { + outputModule: true + }, + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'worker.js', + library: { + type: 'module' + } + }, + externals:{"/router.js":"/router.js"} + }; \ No newline at end of file