Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Sun Jan 10 11:53:12 2021 +0000
Revision:
147:ea6f647725a1
Parent:
146:6bc151bd7063
Child:
148:3d685db9fdd3
Added ability for the user to resolve a name.

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