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:
144:7106252b7abf
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 //Net4 script
andrewboyson 86:f3c9beec4ee7 2 'use strict';
andrewboyson 86:f3c9beec4ee7 3
andrewboyson 95:8c9dda8a0caf 4 let localIp = '';
andrewboyson 95:8c9dda8a0caf 5 let domainName = '';
andrewboyson 95:8c9dda8a0caf 6 let hostName = '';
andrewboyson 95:8c9dda8a0caf 7 let ntpIp = '';
andrewboyson 95:8c9dda8a0caf 8 let dnsIp = '';
andrewboyson 95:8c9dda8a0caf 9 let dhcpIp = '';
andrewboyson 95:8c9dda8a0caf 10 let routerIp = '';
andrewboyson 95:8c9dda8a0caf 11 let subnetMask = '';
andrewboyson 95:8c9dda8a0caf 12 let broadcastIp = '';
andrewboyson 95:8c9dda8a0caf 13 let leaseTime = '';
andrewboyson 95:8c9dda8a0caf 14 let renewalT1 = '';
andrewboyson 95:8c9dda8a0caf 15 let renewalt2 = '';
andrewboyson 95:8c9dda8a0caf 16 let elapsed = '';
andrewboyson 95:8c9dda8a0caf 17 let arp = '';
andrewboyson 95:8c9dda8a0caf 18 let dns = '';
andrewboyson 86:f3c9beec4ee7 19
andrewboyson 88:2857259fc2b4 20 function parseArpLine(line)
andrewboyson 88:2857259fc2b4 21 {
andrewboyson 88:2857259fc2b4 22 if (line.length == 0) return;
andrewboyson 136:be1d42268b5d 23 let fields = line.split('\t');
andrewboyson 136:be1d42268b5d 24
andrewboyson 136:be1d42268b5d 25 arp += parseInt(fields[0], 16).toString().padStart(2, ' ');
andrewboyson 136:be1d42268b5d 26
andrewboyson 136:be1d42268b5d 27 let minutes = parseInt(fields[1], 16) / 1000 / 60;
andrewboyson 88:2857259fc2b4 28 arp += Math.floor(minutes).toString().padStart(4, ' ');
andrewboyson 136:be1d42268b5d 29
andrewboyson 88:2857259fc2b4 30 arp += ' ';
andrewboyson 136:be1d42268b5d 31 arp += Net.makeIp4(fields[2]).padEnd(15, ' ');
andrewboyson 136:be1d42268b5d 32
andrewboyson 88:2857259fc2b4 33 arp += ' ';
andrewboyson 136:be1d42268b5d 34 arp += Net.makeMac(fields[3]);
andrewboyson 136:be1d42268b5d 35
andrewboyson 88:2857259fc2b4 36 arp += '\r\n';
andrewboyson 88:2857259fc2b4 37 }
andrewboyson 88:2857259fc2b4 38 function parseDnsLine(line)
andrewboyson 88:2857259fc2b4 39 {
andrewboyson 88:2857259fc2b4 40 if (line.length == 0) return;
andrewboyson 136:be1d42268b5d 41 let fields = line.split('\t');
andrewboyson 136:be1d42268b5d 42
andrewboyson 136:be1d42268b5d 43 dns += parseInt(fields[0], 16).toString().padStart(2, ' ');
andrewboyson 136:be1d42268b5d 44
andrewboyson 136:be1d42268b5d 45 let minutes = parseInt(fields[1], 16) / 1000 / 60;
andrewboyson 88:2857259fc2b4 46 dns += Math.floor(minutes).toString().padStart(4, ' ');
andrewboyson 88:2857259fc2b4 47 dns += ' ';
andrewboyson 136:be1d42268b5d 48 dns += Net.makeIp4(fields[2]).padEnd(15, ' ');
andrewboyson 88:2857259fc2b4 49 dns += ' ';
andrewboyson 136:be1d42268b5d 50 dns += fields[3];
andrewboyson 88:2857259fc2b4 51 dns += ' ';
andrewboyson 136:be1d42268b5d 52 dns += fields[4];
andrewboyson 88:2857259fc2b4 53 dns += '\r\n';
andrewboyson 88:2857259fc2b4 54 }
andrewboyson 88:2857259fc2b4 55 function parseArpLines(text)
andrewboyson 88:2857259fc2b4 56 {
andrewboyson 88:2857259fc2b4 57 arp = '';
andrewboyson 88:2857259fc2b4 58 text.split('\n').forEach(parseArpLine);
andrewboyson 88:2857259fc2b4 59 }
andrewboyson 88:2857259fc2b4 60 function parseDnsLines(text)
andrewboyson 88:2857259fc2b4 61 {
andrewboyson 88:2857259fc2b4 62 dns = '';
andrewboyson 88:2857259fc2b4 63 text.split('\n').forEach(parseDnsLine);
andrewboyson 88:2857259fc2b4 64 }
andrewboyson 89:615fb951df69 65 function parseGenLines(text)
andrewboyson 89:615fb951df69 66 {
andrewboyson 95:8c9dda8a0caf 67 let lines = text.split('\n');
andrewboyson 96:eb2eb75bad0f 68 localIp = Net.makeIp4(lines[ 0]) ;
andrewboyson 96:eb2eb75bad0f 69 domainName = lines[ 1] ;
andrewboyson 96:eb2eb75bad0f 70 hostName = lines[ 2] ;
andrewboyson 96:eb2eb75bad0f 71 ntpIp = Net.makeIp4(lines[ 3]) ;
andrewboyson 96:eb2eb75bad0f 72 dnsIp = Net.makeIp4(lines[ 4]) ;
andrewboyson 96:eb2eb75bad0f 73 dhcpIp = Net.makeIp4(lines[ 5]) ;
andrewboyson 96:eb2eb75bad0f 74 routerIp = Net.makeIp4(lines[ 6]) ;
andrewboyson 96:eb2eb75bad0f 75 subnetMask = Net.makeIp4(lines[ 7]) ;
andrewboyson 96:eb2eb75bad0f 76 broadcastIp = Net.makeIp4(lines[ 8]) ;
andrewboyson 96:eb2eb75bad0f 77 leaseTime = parseInt(lines[ 9], 16);
andrewboyson 96:eb2eb75bad0f 78 renewalT1 = parseInt(lines[10], 16);
andrewboyson 96:eb2eb75bad0f 79 renewalt2 = parseInt(lines[11], 16);
andrewboyson 96:eb2eb75bad0f 80 elapsed = parseInt(lines[12], 16);
andrewboyson 89:615fb951df69 81 }
andrewboyson 95:8c9dda8a0caf 82 function parse()
andrewboyson 86:f3c9beec4ee7 83 {
andrewboyson 95:8c9dda8a0caf 84 let topics = Ajax.response.split('\f');
andrewboyson 89:615fb951df69 85 parseGenLines(topics[0]);
andrewboyson 89:615fb951df69 86 parseArpLines(topics[1]);
andrewboyson 89:615fb951df69 87 parseDnsLines(topics[2]);
andrewboyson 86:f3c9beec4ee7 88 }
andrewboyson 95:8c9dda8a0caf 89 function display()
andrewboyson 86:f3c9beec4ee7 90 {
andrewboyson 95:8c9dda8a0caf 91 let elem;
andrewboyson 86:f3c9beec4ee7 92
andrewboyson 95:8c9dda8a0caf 93 elem = Ajax.getElementOrNull('ajax-local-ip' ); if (elem) elem.textContent = localIp;
andrewboyson 95:8c9dda8a0caf 94 elem = Ajax.getElementOrNull('ajax-domain-name' ); if (elem) elem.textContent = domainName;
andrewboyson 95:8c9dda8a0caf 95 elem = Ajax.getElementOrNull('ajax-host-name' ); if (elem) elem.textContent = hostName;
andrewboyson 95:8c9dda8a0caf 96 elem = Ajax.getElementOrNull('ajax-ntp-ip' ); if (elem) elem.textContent = ntpIp;
andrewboyson 95:8c9dda8a0caf 97 elem = Ajax.getElementOrNull('ajax-dns-ip' ); if (elem) elem.textContent = dnsIp;
andrewboyson 95:8c9dda8a0caf 98 elem = Ajax.getElementOrNull('ajax-dhcp-ip' ); if (elem) elem.textContent = dhcpIp;
andrewboyson 95:8c9dda8a0caf 99 elem = Ajax.getElementOrNull('ajax-router-ip' ); if (elem) elem.textContent = routerIp;
andrewboyson 95:8c9dda8a0caf 100 elem = Ajax.getElementOrNull('ajax-subnet-mask' ); if (elem) elem.textContent = subnetMask;
andrewboyson 95:8c9dda8a0caf 101 elem = Ajax.getElementOrNull('ajax-broadcast-ip'); if (elem) elem.textContent = broadcastIp;
andrewboyson 95:8c9dda8a0caf 102 elem = Ajax.getElementOrNull('ajax-lease-time' ); if (elem) elem.textContent = leaseTime;
andrewboyson 95:8c9dda8a0caf 103 elem = Ajax.getElementOrNull('ajax-renewal-t1' ); if (elem) elem.textContent = renewalT1;
andrewboyson 95:8c9dda8a0caf 104 elem = Ajax.getElementOrNull('ajax-renewal-t2' ); if (elem) elem.textContent = renewalt2;
andrewboyson 95:8c9dda8a0caf 105 elem = Ajax.getElementOrNull('ajax-elapsed' ); if (elem) elem.textContent = elapsed;
andrewboyson 95:8c9dda8a0caf 106 elem = Ajax.getElementOrNull('ajax-arp' ); if (elem) elem.textContent = arp;
andrewboyson 95:8c9dda8a0caf 107 elem = Ajax.getElementOrNull('ajax-dns' ); if (elem) elem.textContent = dns;
andrewboyson 86:f3c9beec4ee7 108 }
andrewboyson 86:f3c9beec4ee7 109
andrewboyson 95:8c9dda8a0caf 110 Ajax.server = '/net4-ajax';
andrewboyson 95:8c9dda8a0caf 111 Ajax.onResponse = function() { parse(); display(); };
andrewboyson 95:8c9dda8a0caf 112 Ajax.init();