Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Sat Dec 26 20:02:22 2020 +0000
Revision:
144:7106252b7abf
Parent:
136:be1d42268b5d
Child:
146:6bc151bd7063
Moved name resolution web info from IPv4 and IPv6 pages to general net 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 86:f3c9beec4ee7 18
andrewboyson 88:2857259fc2b4 19 function parseArpLine(line)
andrewboyson 88:2857259fc2b4 20 {
andrewboyson 88:2857259fc2b4 21 if (line.length == 0) return;
andrewboyson 136:be1d42268b5d 22 let fields = line.split('\t');
andrewboyson 136:be1d42268b5d 23
andrewboyson 136:be1d42268b5d 24 arp += parseInt(fields[0], 16).toString().padStart(2, ' ');
andrewboyson 136:be1d42268b5d 25
andrewboyson 136:be1d42268b5d 26 let minutes = parseInt(fields[1], 16) / 1000 / 60;
andrewboyson 88:2857259fc2b4 27 arp += Math.floor(minutes).toString().padStart(4, ' ');
andrewboyson 136:be1d42268b5d 28
andrewboyson 88:2857259fc2b4 29 arp += ' ';
andrewboyson 136:be1d42268b5d 30 arp += Net.makeIp4(fields[2]).padEnd(15, ' ');
andrewboyson 136:be1d42268b5d 31
andrewboyson 88:2857259fc2b4 32 arp += ' ';
andrewboyson 136:be1d42268b5d 33 arp += Net.makeMac(fields[3]);
andrewboyson 136:be1d42268b5d 34
andrewboyson 88:2857259fc2b4 35 arp += '\r\n';
andrewboyson 88:2857259fc2b4 36 }
andrewboyson 88:2857259fc2b4 37 function parseArpLines(text)
andrewboyson 88:2857259fc2b4 38 {
andrewboyson 88:2857259fc2b4 39 arp = '';
andrewboyson 88:2857259fc2b4 40 text.split('\n').forEach(parseArpLine);
andrewboyson 88:2857259fc2b4 41 }
andrewboyson 89:615fb951df69 42 function parseGenLines(text)
andrewboyson 89:615fb951df69 43 {
andrewboyson 95:8c9dda8a0caf 44 let lines = text.split('\n');
andrewboyson 96:eb2eb75bad0f 45 localIp = Net.makeIp4(lines[ 0]) ;
andrewboyson 96:eb2eb75bad0f 46 domainName = lines[ 1] ;
andrewboyson 96:eb2eb75bad0f 47 hostName = lines[ 2] ;
andrewboyson 96:eb2eb75bad0f 48 ntpIp = Net.makeIp4(lines[ 3]) ;
andrewboyson 96:eb2eb75bad0f 49 dnsIp = Net.makeIp4(lines[ 4]) ;
andrewboyson 96:eb2eb75bad0f 50 dhcpIp = Net.makeIp4(lines[ 5]) ;
andrewboyson 96:eb2eb75bad0f 51 routerIp = Net.makeIp4(lines[ 6]) ;
andrewboyson 96:eb2eb75bad0f 52 subnetMask = Net.makeIp4(lines[ 7]) ;
andrewboyson 96:eb2eb75bad0f 53 broadcastIp = Net.makeIp4(lines[ 8]) ;
andrewboyson 96:eb2eb75bad0f 54 leaseTime = parseInt(lines[ 9], 16);
andrewboyson 96:eb2eb75bad0f 55 renewalT1 = parseInt(lines[10], 16);
andrewboyson 96:eb2eb75bad0f 56 renewalt2 = parseInt(lines[11], 16);
andrewboyson 96:eb2eb75bad0f 57 elapsed = parseInt(lines[12], 16);
andrewboyson 89:615fb951df69 58 }
andrewboyson 95:8c9dda8a0caf 59 function parse()
andrewboyson 86:f3c9beec4ee7 60 {
andrewboyson 95:8c9dda8a0caf 61 let topics = Ajax.response.split('\f');
andrewboyson 89:615fb951df69 62 parseGenLines(topics[0]);
andrewboyson 89:615fb951df69 63 parseArpLines(topics[1]);
andrewboyson 86:f3c9beec4ee7 64 }
andrewboyson 95:8c9dda8a0caf 65 function display()
andrewboyson 86:f3c9beec4ee7 66 {
andrewboyson 95:8c9dda8a0caf 67 let elem;
andrewboyson 86:f3c9beec4ee7 68
andrewboyson 95:8c9dda8a0caf 69 elem = Ajax.getElementOrNull('ajax-local-ip' ); if (elem) elem.textContent = localIp;
andrewboyson 95:8c9dda8a0caf 70 elem = Ajax.getElementOrNull('ajax-domain-name' ); if (elem) elem.textContent = domainName;
andrewboyson 95:8c9dda8a0caf 71 elem = Ajax.getElementOrNull('ajax-host-name' ); if (elem) elem.textContent = hostName;
andrewboyson 95:8c9dda8a0caf 72 elem = Ajax.getElementOrNull('ajax-ntp-ip' ); if (elem) elem.textContent = ntpIp;
andrewboyson 95:8c9dda8a0caf 73 elem = Ajax.getElementOrNull('ajax-dns-ip' ); if (elem) elem.textContent = dnsIp;
andrewboyson 95:8c9dda8a0caf 74 elem = Ajax.getElementOrNull('ajax-dhcp-ip' ); if (elem) elem.textContent = dhcpIp;
andrewboyson 95:8c9dda8a0caf 75 elem = Ajax.getElementOrNull('ajax-router-ip' ); if (elem) elem.textContent = routerIp;
andrewboyson 95:8c9dda8a0caf 76 elem = Ajax.getElementOrNull('ajax-subnet-mask' ); if (elem) elem.textContent = subnetMask;
andrewboyson 95:8c9dda8a0caf 77 elem = Ajax.getElementOrNull('ajax-broadcast-ip'); if (elem) elem.textContent = broadcastIp;
andrewboyson 95:8c9dda8a0caf 78 elem = Ajax.getElementOrNull('ajax-lease-time' ); if (elem) elem.textContent = leaseTime;
andrewboyson 95:8c9dda8a0caf 79 elem = Ajax.getElementOrNull('ajax-renewal-t1' ); if (elem) elem.textContent = renewalT1;
andrewboyson 95:8c9dda8a0caf 80 elem = Ajax.getElementOrNull('ajax-renewal-t2' ); if (elem) elem.textContent = renewalt2;
andrewboyson 95:8c9dda8a0caf 81 elem = Ajax.getElementOrNull('ajax-elapsed' ); if (elem) elem.textContent = elapsed;
andrewboyson 95:8c9dda8a0caf 82 elem = Ajax.getElementOrNull('ajax-arp' ); if (elem) elem.textContent = arp;
andrewboyson 86:f3c9beec4ee7 83 }
andrewboyson 86:f3c9beec4ee7 84
andrewboyson 95:8c9dda8a0caf 85 Ajax.server = '/net4-ajax';
andrewboyson 95:8c9dda8a0caf 86 Ajax.onResponse = function() { parse(); display(); };
andrewboyson 95:8c9dda8a0caf 87 Ajax.init();