Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Thu Apr 02 19:10:57 2020 +0000
Revision:
136:be1d42268b5d
Parent:
110:8ab752842d25
Child:
142:b472ba95b018
Modified the IPv4 and IPv6 pages to display the resolution indexes for cross referencing against the TCP page

Who changed what in which revision?

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