Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Mon Jan 04 16:09:03 2021 +0000
Revision:
146:6bc151bd7063
Parent:
144:7106252b7abf
Modified Name and address resolution to include vendor names

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 96:eb2eb75bad0f 1 "//Net6 script\n"
andrewboyson 86:f3c9beec4ee7 2 "'use strict';\n"
andrewboyson 86:f3c9beec4ee7 3 "\n"
andrewboyson 96:eb2eb75bad0f 4 "let arp = '';\n"
andrewboyson 142:b472ba95b018 5 "\n"
andrewboyson 96:eb2eb75bad0f 6 "let hopLimit = '';\n"
andrewboyson 142:b472ba95b018 7 "let mtu = '';\n"
andrewboyson 96:eb2eb75bad0f 8 "let managed = false;\n"
andrewboyson 96:eb2eb75bad0f 9 "let other = false;\n"
andrewboyson 96:eb2eb75bad0f 10 "let routerMac = '';\n"
andrewboyson 96:eb2eb75bad0f 11 "let dnsLife = '';\n"
andrewboyson 96:eb2eb75bad0f 12 "let dnsIp = '';\n"
andrewboyson 96:eb2eb75bad0f 13 "let ndpLease = '';\n"
andrewboyson 96:eb2eb75bad0f 14 "let ndpElapsed = '';\n"
andrewboyson 96:eb2eb75bad0f 15 "let slaac = '';\n"
andrewboyson 142:b472ba95b018 16 "\n"
andrewboyson 142:b472ba95b018 17 "let uniquePrefixLength = '';\n"
andrewboyson 142:b472ba95b018 18 "let uniquePrefixL = false;\n"
andrewboyson 142:b472ba95b018 19 "let uniquePrefixA = false;\n"
andrewboyson 142:b472ba95b018 20 "let uniquePrefixLimit = '';\n"
andrewboyson 142:b472ba95b018 21 "let uniquePrefixPreferred = '';\n"
andrewboyson 142:b472ba95b018 22 "let uniquePrefix = '';\n"
andrewboyson 142:b472ba95b018 23 "let globalPrefixLength = '';\n"
andrewboyson 142:b472ba95b018 24 "let globalPrefixL = false;\n"
andrewboyson 142:b472ba95b018 25 "let globalPrefixA = false;\n"
andrewboyson 142:b472ba95b018 26 "let globalPrefixLimit = '';\n"
andrewboyson 142:b472ba95b018 27 "let globalPrefixPreferred = '';\n"
andrewboyson 142:b472ba95b018 28 "let globalPrefix = '';\n"
andrewboyson 86:f3c9beec4ee7 29 "\n"
andrewboyson 88:2857259fc2b4 30 "function parseArpLine(line)\n"
andrewboyson 88:2857259fc2b4 31 "{\n"
andrewboyson 88:2857259fc2b4 32 " if (line.length == 0) return;\n"
andrewboyson 136:be1d42268b5d 33 " let fields = line.split('\\t');\n"
andrewboyson 136:be1d42268b5d 34 " \n"
andrewboyson 136:be1d42268b5d 35 " arp += parseInt(fields[0], 16).toString().padStart(2, ' ');\n"
andrewboyson 136:be1d42268b5d 36 " \n"
andrewboyson 136:be1d42268b5d 37 " let minutes = parseInt(fields[1], 16) / 1000 / 60;\n"
andrewboyson 88:2857259fc2b4 38 " arp += Math.floor(minutes).toString().padStart(4, ' ');\n"
andrewboyson 146:6bc151bd7063 39 " \n"
andrewboyson 88:2857259fc2b4 40 " arp += ' ';\n"
andrewboyson 136:be1d42268b5d 41 " arp += Net.makeIp6(fields[2]).padEnd(40, ' ');\n"
andrewboyson 146:6bc151bd7063 42 " \n"
andrewboyson 88:2857259fc2b4 43 " arp += ' ';\n"
andrewboyson 146:6bc151bd7063 44 " let mac = Net.makeMac(fields[3]);\n"
andrewboyson 146:6bc151bd7063 45 " arp += mac;\n"
andrewboyson 136:be1d42268b5d 46 " \n"
andrewboyson 146:6bc151bd7063 47 " let vendor = Net.getVendorFromLocalStorage(mac);\n"
andrewboyson 146:6bc151bd7063 48 " if (vendor)\n"
andrewboyson 146:6bc151bd7063 49 " {\n"
andrewboyson 146:6bc151bd7063 50 " arp += ' ';\n"
andrewboyson 146:6bc151bd7063 51 " arp += vendor;\n"
andrewboyson 146:6bc151bd7063 52 " }\n"
andrewboyson 146:6bc151bd7063 53 " else\n"
andrewboyson 146:6bc151bd7063 54 " {\n"
andrewboyson 146:6bc151bd7063 55 " Net.addVendorToLocalStorage(mac);\n"
andrewboyson 146:6bc151bd7063 56 " }\n"
andrewboyson 146:6bc151bd7063 57 " \n"
andrewboyson 88:2857259fc2b4 58 " arp += '\\r\\n';\n"
andrewboyson 88:2857259fc2b4 59 "}\n"
andrewboyson 88:2857259fc2b4 60 "function parseArpLines(text)\n"
andrewboyson 88:2857259fc2b4 61 "{\n"
andrewboyson 88:2857259fc2b4 62 " arp = '';\n"
andrewboyson 88:2857259fc2b4 63 " text.split('\\n').forEach(parseArpLine);\n"
andrewboyson 88:2857259fc2b4 64 "}\n"
andrewboyson 89:615fb951df69 65 "function parseGenLines(text)\n"
andrewboyson 89:615fb951df69 66 "{\n"
andrewboyson 96:eb2eb75bad0f 67 " let lines = text.split('\\n');\n"
andrewboyson 89:615fb951df69 68 " \n"
andrewboyson 142:b472ba95b018 69 " slaac = Net.makeIp6 (lines[ 0] );\n"
andrewboyson 142:b472ba95b018 70 " \n"
andrewboyson 142:b472ba95b018 71 " hopLimit = parseInt(lines[ 1], 16);\n"
andrewboyson 142:b472ba95b018 72 " mtu = parseInt(lines[ 2], 16);\n"
andrewboyson 142:b472ba95b018 73 " managed = Net.hexToBit(lines[ 3], 0);\n"
andrewboyson 142:b472ba95b018 74 " other = Net.hexToBit(lines[ 3], 1);\n"
andrewboyson 142:b472ba95b018 75 " routerMac = Net.makeMac (lines[ 4], 16);\n"
andrewboyson 142:b472ba95b018 76 " ndpLease = parseInt(lines[ 5], 16);\n"
andrewboyson 142:b472ba95b018 77 " ndpElapsed = parseInt(lines[ 6], 16);\n"
andrewboyson 142:b472ba95b018 78 " \n"
andrewboyson 142:b472ba95b018 79 " dnsIp = Net.makeIp6 (lines[ 7] );\n"
andrewboyson 142:b472ba95b018 80 " dnsLife = parseInt(lines[ 8], 16);\n"
andrewboyson 142:b472ba95b018 81 " \n"
andrewboyson 142:b472ba95b018 82 " uniquePrefixL = Net.hexToBit(lines[ 9], 0);\n"
andrewboyson 142:b472ba95b018 83 " uniquePrefixA = Net.hexToBit(lines[ 9], 1);\n"
andrewboyson 142:b472ba95b018 84 " uniquePrefixLength = parseInt(lines[10], 16);\n"
andrewboyson 142:b472ba95b018 85 " uniquePrefix = Net.makeIp6 (lines[11] );\n"
andrewboyson 142:b472ba95b018 86 " uniquePrefixLimit = parseInt(lines[12], 16);\n"
andrewboyson 142:b472ba95b018 87 " uniquePrefixPreferred = parseInt(lines[13], 16);\n"
andrewboyson 142:b472ba95b018 88 " \n"
andrewboyson 142:b472ba95b018 89 " globalPrefixL = Net.hexToBit(lines[14], 0);\n"
andrewboyson 142:b472ba95b018 90 " globalPrefixA = Net.hexToBit(lines[14], 1);\n"
andrewboyson 142:b472ba95b018 91 " globalPrefixLength = parseInt(lines[15], 16);\n"
andrewboyson 142:b472ba95b018 92 " globalPrefix = Net.makeIp6 (lines[16] );\n"
andrewboyson 142:b472ba95b018 93 " globalPrefixLimit = parseInt(lines[17], 16);\n"
andrewboyson 142:b472ba95b018 94 " globalPrefixPreferred = parseInt(lines[18], 16);\n"
andrewboyson 89:615fb951df69 95 "}\n"
andrewboyson 96:eb2eb75bad0f 96 "function parse()\n"
andrewboyson 86:f3c9beec4ee7 97 "{\n"
andrewboyson 96:eb2eb75bad0f 98 " let topics = Ajax.response.split('\\f');\n"
andrewboyson 89:615fb951df69 99 " parseGenLines(topics[0]);\n"
andrewboyson 89:615fb951df69 100 " parseArpLines(topics[1]);\n"
andrewboyson 86:f3c9beec4ee7 101 "}\n"
andrewboyson 96:eb2eb75bad0f 102 "function display()\n"
andrewboyson 86:f3c9beec4ee7 103 "{\n"
andrewboyson 96:eb2eb75bad0f 104 " let elem;\n"
andrewboyson 89:615fb951df69 105 " \n"
andrewboyson 96:eb2eb75bad0f 106 " elem = Ajax.getElementOrNull('ajax-arp' ); if (elem) elem.textContent = arp;\n"
andrewboyson 142:b472ba95b018 107 " elem = Ajax.getElementOrNull('ajax-slaac' ); if (elem) elem.textContent = slaac;\n"
andrewboyson 96:eb2eb75bad0f 108 " elem = Ajax.getElementOrNull('ajax-hop-limit' ); if (elem) elem.textContent = hopLimit;\n"
andrewboyson 142:b472ba95b018 109 " elem = Ajax.getElementOrNull('ajax-mtu' ); if (elem) elem.textContent = mtu;\n"
andrewboyson 96:eb2eb75bad0f 110 " elem = Ajax.getElementOrNull('ajax-managed' ); if (elem) elem.setAttribute('dir', managed ? 'rtl' : 'ltr');\n"
andrewboyson 96:eb2eb75bad0f 111 " elem = Ajax.getElementOrNull('ajax-other' ); if (elem) elem.setAttribute('dir', other ? 'rtl' : 'ltr');\n"
andrewboyson 96:eb2eb75bad0f 112 " elem = Ajax.getElementOrNull('ajax-router-mac' ); if (elem) elem.textContent = routerMac;\n"
andrewboyson 142:b472ba95b018 113 " elem = Ajax.getElementOrNull('ajax-ndp-lease' ); if (elem) elem.textContent = ndpLease;\n"
andrewboyson 142:b472ba95b018 114 " elem = Ajax.getElementOrNull('ajax-ndp-elapsed' ); if (elem) elem.textContent = ndpElapsed;\n"
andrewboyson 96:eb2eb75bad0f 115 " elem = Ajax.getElementOrNull('ajax-dns-life' ); if (elem) elem.textContent = dnsLife;\n"
andrewboyson 96:eb2eb75bad0f 116 " elem = Ajax.getElementOrNull('ajax-dns-ip' ); if (elem) elem.textContent = dnsIp;\n"
andrewboyson 142:b472ba95b018 117 " \n"
andrewboyson 142:b472ba95b018 118 " elem = Ajax.getElementOrNull('ajax-unique-prefix-l' ); if (elem) elem.setAttribute('dir', uniquePrefixL ? 'rtl' : 'ltr');\n"
andrewboyson 142:b472ba95b018 119 " elem = Ajax.getElementOrNull('ajax-unique-prefix-a' ); if (elem) elem.setAttribute('dir', uniquePrefixA ? 'rtl' : 'ltr');\n"
andrewboyson 142:b472ba95b018 120 " elem = Ajax.getElementOrNull('ajax-unique-prefix-length' ); if (elem) elem.textContent = uniquePrefixLength;\n"
andrewboyson 142:b472ba95b018 121 " elem = Ajax.getElementOrNull('ajax-unique-prefix' ); if (elem) elem.textContent = uniquePrefix;\n"
andrewboyson 142:b472ba95b018 122 " elem = Ajax.getElementOrNull('ajax-unique-prefix-limit' ); if (elem) elem.textContent = uniquePrefixLimit;\n"
andrewboyson 142:b472ba95b018 123 " elem = Ajax.getElementOrNull('ajax-unique-prefix-preferred'); if (elem) elem.textContent = uniquePrefixPreferred;\n"
andrewboyson 142:b472ba95b018 124 " \n"
andrewboyson 142:b472ba95b018 125 " elem = Ajax.getElementOrNull('ajax-global-prefix-l' ); if (elem) elem.setAttribute('dir', globalPrefixL ? 'rtl' : 'ltr');\n"
andrewboyson 142:b472ba95b018 126 " elem = Ajax.getElementOrNull('ajax-global-prefix-a' ); if (elem) elem.setAttribute('dir', globalPrefixA ? 'rtl' : 'ltr');\n"
andrewboyson 142:b472ba95b018 127 " elem = Ajax.getElementOrNull('ajax-global-prefix-length' ); if (elem) elem.textContent = globalPrefixLength;\n"
andrewboyson 142:b472ba95b018 128 " elem = Ajax.getElementOrNull('ajax-global-prefix' ); if (elem) elem.textContent = globalPrefix;\n"
andrewboyson 142:b472ba95b018 129 " elem = Ajax.getElementOrNull('ajax-global-prefix-limit' ); if (elem) elem.textContent = globalPrefixLimit;\n"
andrewboyson 142:b472ba95b018 130 " elem = Ajax.getElementOrNull('ajax-global-prefix-preferred'); if (elem) elem.textContent = globalPrefixPreferred;\n"
andrewboyson 86:f3c9beec4ee7 131 "}\n"
andrewboyson 86:f3c9beec4ee7 132 "\n"
andrewboyson 96:eb2eb75bad0f 133 "Ajax.server = '/net6-ajax';\n"
andrewboyson 96:eb2eb75bad0f 134 "Ajax.onResponse = function() { parse(); display(); };\n"
andrewboyson 96:eb2eb75bad0f 135 "Ajax.init();"