Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Mon Jan 04 16:09:03 2021 +0000
Revision:
146:6bc151bd7063
Parent:
145:d2bd78be00b2
Child:
147:ea6f647725a1
Modified Name and address resolution to include vendor names

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 132:5b2df69a4f17 1 "//Net script\n"
andrewboyson 132:5b2df69a4f17 2 "'use strict';\n"
andrewboyson 132:5b2df69a4f17 3 "\n"
andrewboyson 132:5b2df69a4f17 4 "let mac = '';\n"
andrewboyson 132:5b2df69a4f17 5 "let tcp = '';\n"
andrewboyson 143:cc2e148cb96a 6 "let dns = '';\n"
andrewboyson 146:6bc151bd7063 7 "let a4s = null;\n"
andrewboyson 146:6bc151bd7063 8 "let a6s = null;\n"
andrewboyson 132:5b2df69a4f17 9 "\n"
andrewboyson 132:5b2df69a4f17 10 "function parseTcpLine(line)\n"
andrewboyson 132:5b2df69a4f17 11 "{\n"
andrewboyson 132:5b2df69a4f17 12 " if (line.length == 0) return;\n"
andrewboyson 132:5b2df69a4f17 13 " let fields = line.split('\\t');\n"
andrewboyson 133:98c6bf14bc37 14 " let state = parseInt(fields[0], 16);\n"
andrewboyson 133:98c6bf14bc37 15 " let idleMs = parseInt(fields[1], 16);\n"
andrewboyson 133:98c6bf14bc37 16 " let ipType = parseInt(fields[2], 16);\n"
andrewboyson 133:98c6bf14bc37 17 " let arIndex = parseInt(fields[3], 16);\n"
andrewboyson 133:98c6bf14bc37 18 " let locPort = parseInt(fields[4], 16);\n"
andrewboyson 133:98c6bf14bc37 19 " let remPort = parseInt(fields[5], 16);\n"
andrewboyson 133:98c6bf14bc37 20 " let bytesRcvd = parseInt(fields[6], 16);\n"
andrewboyson 133:98c6bf14bc37 21 " let bytesSent = parseInt(fields[7], 16);\n"
andrewboyson 132:5b2df69a4f17 22 " \n"
andrewboyson 133:98c6bf14bc37 23 " switch (state)\n"
andrewboyson 133:98c6bf14bc37 24 " {\n"
andrewboyson 143:cc2e148cb96a 25 " case 1: tcp += \" Syn\"; break;\n"
andrewboyson 143:cc2e148cb96a 26 " case 2: tcp += \" Est\"; break;\n"
andrewboyson 143:cc2e148cb96a 27 " case 3: tcp += \" Wait\"; break;\n"
andrewboyson 133:98c6bf14bc37 28 " default: tcp += state.toString().padStart(5, ' '); break;\n"
andrewboyson 133:98c6bf14bc37 29 " }\n"
andrewboyson 132:5b2df69a4f17 30 " \n"
andrewboyson 133:98c6bf14bc37 31 " let idleMinutes = Math.floor(idleMs / 1000 / 60);\n"
andrewboyson 133:98c6bf14bc37 32 " tcp += idleMinutes.toString().padStart(4, ' ');\n"
andrewboyson 133:98c6bf14bc37 33 " tcp += \" \";\n"
andrewboyson 132:5b2df69a4f17 34 " \n"
andrewboyson 133:98c6bf14bc37 35 " if (ipType == 0x0800) tcp += \"IPv4\";\n"
andrewboyson 132:5b2df69a4f17 36 " else if (ipType == 0x86DD) tcp += \"IPv6\";\n"
andrewboyson 132:5b2df69a4f17 37 " else tcp += fields[1];\n"
andrewboyson 132:5b2df69a4f17 38 " \n"
andrewboyson 133:98c6bf14bc37 39 " tcp += arIndex.toString().padStart(4, ' ');\n"
andrewboyson 133:98c6bf14bc37 40 " tcp += locPort.toString().padStart(9, ' ');\n"
andrewboyson 133:98c6bf14bc37 41 " tcp += remPort.toString().padStart(9, ' ');\n"
andrewboyson 133:98c6bf14bc37 42 " tcp += bytesRcvd.toString().padStart(6, ' ');\n"
andrewboyson 133:98c6bf14bc37 43 " tcp += bytesSent.toString().padStart(6, ' ');\n"
andrewboyson 132:5b2df69a4f17 44 " tcp += '\\r\\n';\n"
andrewboyson 132:5b2df69a4f17 45 "}\n"
andrewboyson 143:cc2e148cb96a 46 "function parseDnsLine(line)\n"
andrewboyson 143:cc2e148cb96a 47 "{\n"
andrewboyson 143:cc2e148cb96a 48 " if (line.length == 0) return;\n"
andrewboyson 143:cc2e148cb96a 49 " let fields = line.split('\\t');\n"
andrewboyson 143:cc2e148cb96a 50 " \n"
andrewboyson 143:cc2e148cb96a 51 " dns += parseInt(fields[0], 16).toString().padStart(2, ' ');\n"
andrewboyson 143:cc2e148cb96a 52 " let minutes = parseInt(fields[1], 16) / 1000 / 60;\n"
andrewboyson 143:cc2e148cb96a 53 " dns += Math.floor(minutes).toString().padStart(4, ' ');\n"
andrewboyson 143:cc2e148cb96a 54 " dns += ' ';\n"
andrewboyson 146:6bc151bd7063 55 " let addr = '';\n"
andrewboyson 146:6bc151bd7063 56 " let mac = '';\n"
andrewboyson 145:d2bd78be00b2 57 " if (fields[2].substr( 0, 2) === '00') //Is empty or IP4\n"
andrewboyson 145:d2bd78be00b2 58 " {\n"
andrewboyson 145:d2bd78be00b2 59 " if (fields[2].substr(24, 2) === '00') //Is empty\n"
andrewboyson 145:d2bd78be00b2 60 " {\n"
andrewboyson 146:6bc151bd7063 61 " addr = '';\n"
andrewboyson 145:d2bd78be00b2 62 " }\n"
andrewboyson 145:d2bd78be00b2 63 " else //Is Ip4\n"
andrewboyson 145:d2bd78be00b2 64 " {\n"
andrewboyson 146:6bc151bd7063 65 " addr = Net.makeIp4Rev(fields[2].substr(24, 8));\n"
andrewboyson 146:6bc151bd7063 66 " if (a4s.has(addr)) mac = a4s.get(addr);\n"
andrewboyson 145:d2bd78be00b2 67 " }\n"
andrewboyson 145:d2bd78be00b2 68 " }\n"
andrewboyson 145:d2bd78be00b2 69 " else //Is IP6\n"
andrewboyson 145:d2bd78be00b2 70 " {\n"
andrewboyson 146:6bc151bd7063 71 " addr = Net.makeIp6(fields[2]);\n"
andrewboyson 146:6bc151bd7063 72 " if (a6s.has(addr)) mac = a6s.get(addr)\n"
andrewboyson 145:d2bd78be00b2 73 " }\n"
andrewboyson 146:6bc151bd7063 74 " dns += addr.padEnd(40, ' ');\n"
andrewboyson 146:6bc151bd7063 75 " \n"
andrewboyson 146:6bc151bd7063 76 " dns += ' ';\n"
andrewboyson 146:6bc151bd7063 77 " dns += fields[3]; //DNS protocol used\n"
andrewboyson 143:cc2e148cb96a 78 " dns += ' ';\n"
andrewboyson 146:6bc151bd7063 79 " dns += fields[4].padEnd(20, ' '); //Resolved name\n"
andrewboyson 146:6bc151bd7063 80 " \n"
andrewboyson 146:6bc151bd7063 81 " if (mac != '')\n"
andrewboyson 146:6bc151bd7063 82 " {\n"
andrewboyson 146:6bc151bd7063 83 " dns += ' ';\n"
andrewboyson 146:6bc151bd7063 84 " dns += mac;\n"
andrewboyson 146:6bc151bd7063 85 " dns += ' ';\n"
andrewboyson 146:6bc151bd7063 86 " \n"
andrewboyson 146:6bc151bd7063 87 " let vendor = Net.getVendorFromLocalStorage(mac);\n"
andrewboyson 146:6bc151bd7063 88 " if (vendor)\n"
andrewboyson 146:6bc151bd7063 89 " {\n"
andrewboyson 146:6bc151bd7063 90 " dns += ' ';\n"
andrewboyson 146:6bc151bd7063 91 " dns += vendor;\n"
andrewboyson 146:6bc151bd7063 92 " }\n"
andrewboyson 146:6bc151bd7063 93 " else\n"
andrewboyson 146:6bc151bd7063 94 " {\n"
andrewboyson 146:6bc151bd7063 95 " Net.addVendorToLocalStorage(mac);\n"
andrewboyson 146:6bc151bd7063 96 " }\n"
andrewboyson 146:6bc151bd7063 97 " }\n"
andrewboyson 143:cc2e148cb96a 98 " dns += '\\r\\n';\n"
andrewboyson 143:cc2e148cb96a 99 "}\n"
andrewboyson 146:6bc151bd7063 100 "function parseAr4Line(line)\n"
andrewboyson 146:6bc151bd7063 101 "{\n"
andrewboyson 146:6bc151bd7063 102 " if (line.length == 0) return;\n"
andrewboyson 146:6bc151bd7063 103 " let fields = line.split('\\t');\n"
andrewboyson 146:6bc151bd7063 104 " \n"
andrewboyson 146:6bc151bd7063 105 " let index = parseInt(fields[0], 16);\n"
andrewboyson 146:6bc151bd7063 106 " let ms = parseInt(fields[1], 16);\n"
andrewboyson 146:6bc151bd7063 107 " let addr = Net.makeIp4(fields[2]);\n"
andrewboyson 146:6bc151bd7063 108 " let mac = Net.makeMac(fields[3]);\n"
andrewboyson 146:6bc151bd7063 109 " \n"
andrewboyson 146:6bc151bd7063 110 " a4s.set(addr, mac);\n"
andrewboyson 146:6bc151bd7063 111 "}\n"
andrewboyson 146:6bc151bd7063 112 "function parseAr6Line(line)\n"
andrewboyson 146:6bc151bd7063 113 "{\n"
andrewboyson 146:6bc151bd7063 114 " if (line.length == 0) return;\n"
andrewboyson 146:6bc151bd7063 115 " let fields = line.split('\\t');\n"
andrewboyson 146:6bc151bd7063 116 " \n"
andrewboyson 146:6bc151bd7063 117 " let index = parseInt(fields[0], 16);\n"
andrewboyson 146:6bc151bd7063 118 " let ms = parseInt(fields[1], 16);\n"
andrewboyson 146:6bc151bd7063 119 " let addr = Net.makeIp6(fields[2]);\n"
andrewboyson 146:6bc151bd7063 120 " let mac = Net.makeMac(fields[3]);\n"
andrewboyson 146:6bc151bd7063 121 " \n"
andrewboyson 146:6bc151bd7063 122 " a6s.set(addr, mac);\n"
andrewboyson 146:6bc151bd7063 123 "}\n"
andrewboyson 146:6bc151bd7063 124 "function parseGenLines(text)\n"
andrewboyson 146:6bc151bd7063 125 "{\n"
andrewboyson 146:6bc151bd7063 126 " let lines = text.split('\\n');\n"
andrewboyson 146:6bc151bd7063 127 " mac = Net.makeMac(lines[ 0]);\n"
andrewboyson 146:6bc151bd7063 128 "}\n"
andrewboyson 146:6bc151bd7063 129 "function parseTcpLines(text)\n"
andrewboyson 146:6bc151bd7063 130 "{\n"
andrewboyson 146:6bc151bd7063 131 " tcp = \"State Idle Protocol ARI Port-Loc Port-Rem Rcvd Sent\\n\";\n"
andrewboyson 146:6bc151bd7063 132 " text.split('\\n').forEach(parseTcpLine);\n"
andrewboyson 146:6bc151bd7063 133 "}\n"
andrewboyson 144:7106252b7abf 134 "function parseDnsLines(text)\n"
andrewboyson 144:7106252b7abf 135 "{\n"
andrewboyson 144:7106252b7abf 136 " dns = '';\n"
andrewboyson 144:7106252b7abf 137 " text.split('\\n').forEach(parseDnsLine);\n"
andrewboyson 144:7106252b7abf 138 "}\n"
andrewboyson 146:6bc151bd7063 139 "function parseAr4Lines(text)\n"
andrewboyson 132:5b2df69a4f17 140 "{\n"
andrewboyson 146:6bc151bd7063 141 " a4s = new Map();\n"
andrewboyson 146:6bc151bd7063 142 " text.split('\\n').forEach(parseAr4Line);\n"
andrewboyson 146:6bc151bd7063 143 "}\n"
andrewboyson 146:6bc151bd7063 144 "function parseAr6Lines(text)\n"
andrewboyson 146:6bc151bd7063 145 "{\n"
andrewboyson 146:6bc151bd7063 146 " a6s = new Map();\n"
andrewboyson 146:6bc151bd7063 147 " text.split('\\n').forEach(parseAr6Line);\n"
andrewboyson 132:5b2df69a4f17 148 "}\n"
andrewboyson 132:5b2df69a4f17 149 "function parse()\n"
andrewboyson 132:5b2df69a4f17 150 "{\n"
andrewboyson 132:5b2df69a4f17 151 " let topics = Ajax.response.split('\\f');\n"
andrewboyson 132:5b2df69a4f17 152 " parseGenLines(topics[0]);\n"
andrewboyson 132:5b2df69a4f17 153 " parseTcpLines(topics[1]);\n"
andrewboyson 146:6bc151bd7063 154 " parseAr4Lines(topics[3]);\n"
andrewboyson 146:6bc151bd7063 155 " parseAr6Lines(topics[4]);\n"
andrewboyson 143:cc2e148cb96a 156 " parseDnsLines(topics[2]);\n"
andrewboyson 132:5b2df69a4f17 157 "}\n"
andrewboyson 132:5b2df69a4f17 158 "function display()\n"
andrewboyson 132:5b2df69a4f17 159 "{\n"
andrewboyson 132:5b2df69a4f17 160 " let elem;\n"
andrewboyson 132:5b2df69a4f17 161 "\n"
andrewboyson 132:5b2df69a4f17 162 " elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp;\n"
andrewboyson 132:5b2df69a4f17 163 " elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac;\n"
andrewboyson 143:cc2e148cb96a 164 " elem = Ajax.getElementOrNull('ajax-dns' ); if (elem) elem.textContent = dns;\n"
andrewboyson 132:5b2df69a4f17 165 "}\n"
andrewboyson 132:5b2df69a4f17 166 "\n"
andrewboyson 132:5b2df69a4f17 167 "Ajax.server = '/net-ajax';\n"
andrewboyson 132:5b2df69a4f17 168 "Ajax.onResponse = function() { parse(); display(); };\n"
andrewboyson 132:5b2df69a4f17 169 "Ajax.init();\n"
andrewboyson 132:5b2df69a4f17 170 ""