Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Sat Dec 26 20:02:22 2020 +0000
Revision:
144:7106252b7abf
Parent:
143:cc2e148cb96a
Child:
145:d2bd78be00b2
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 132:5b2df69a4f17 1 //Net script
andrewboyson 132:5b2df69a4f17 2 'use strict';
andrewboyson 132:5b2df69a4f17 3
andrewboyson 132:5b2df69a4f17 4 let mac = '';
andrewboyson 132:5b2df69a4f17 5 let tcp = '';
andrewboyson 143:cc2e148cb96a 6 let dns = '';
andrewboyson 132:5b2df69a4f17 7
andrewboyson 132:5b2df69a4f17 8 function parseTcpLine(line)
andrewboyson 132:5b2df69a4f17 9 {
andrewboyson 132:5b2df69a4f17 10 if (line.length == 0) return;
andrewboyson 132:5b2df69a4f17 11 let fields = line.split('\t');
andrewboyson 133:98c6bf14bc37 12 let state = parseInt(fields[0], 16);
andrewboyson 133:98c6bf14bc37 13 let idleMs = parseInt(fields[1], 16);
andrewboyson 133:98c6bf14bc37 14 let ipType = parseInt(fields[2], 16);
andrewboyson 133:98c6bf14bc37 15 let arIndex = parseInt(fields[3], 16);
andrewboyson 133:98c6bf14bc37 16 let locPort = parseInt(fields[4], 16);
andrewboyson 133:98c6bf14bc37 17 let remPort = parseInt(fields[5], 16);
andrewboyson 133:98c6bf14bc37 18 let bytesRcvd = parseInt(fields[6], 16);
andrewboyson 133:98c6bf14bc37 19 let bytesSent = parseInt(fields[7], 16);
andrewboyson 132:5b2df69a4f17 20
andrewboyson 133:98c6bf14bc37 21 switch (state)
andrewboyson 133:98c6bf14bc37 22 {
andrewboyson 133:98c6bf14bc37 23 case 1: tcp += " Syn"; break;
andrewboyson 133:98c6bf14bc37 24 case 2: tcp += " Est"; break;
andrewboyson 133:98c6bf14bc37 25 case 3: tcp += " Wait"; break;
andrewboyson 133:98c6bf14bc37 26 default: tcp += state.toString().padStart(5, ' '); break;
andrewboyson 133:98c6bf14bc37 27 }
andrewboyson 132:5b2df69a4f17 28
andrewboyson 133:98c6bf14bc37 29 let idleMinutes = Math.floor(idleMs / 1000 / 60);
andrewboyson 133:98c6bf14bc37 30 tcp += idleMinutes.toString().padStart(4, ' ');
andrewboyson 133:98c6bf14bc37 31 tcp += " ";
andrewboyson 132:5b2df69a4f17 32
andrewboyson 133:98c6bf14bc37 33 if (ipType == 0x0800) tcp += "IPv4";
andrewboyson 132:5b2df69a4f17 34 else if (ipType == 0x86DD) tcp += "IPv6";
andrewboyson 132:5b2df69a4f17 35 else tcp += fields[1];
andrewboyson 132:5b2df69a4f17 36
andrewboyson 133:98c6bf14bc37 37 tcp += arIndex.toString().padStart(4, ' ');
andrewboyson 133:98c6bf14bc37 38 tcp += locPort.toString().padStart(9, ' ');
andrewboyson 133:98c6bf14bc37 39 tcp += remPort.toString().padStart(9, ' ');
andrewboyson 133:98c6bf14bc37 40 tcp += bytesRcvd.toString().padStart(6, ' ');
andrewboyson 133:98c6bf14bc37 41 tcp += bytesSent.toString().padStart(6, ' ');
andrewboyson 132:5b2df69a4f17 42 tcp += '\r\n';
andrewboyson 132:5b2df69a4f17 43 }
andrewboyson 132:5b2df69a4f17 44 function parseTcpLines(text)
andrewboyson 132:5b2df69a4f17 45 {
andrewboyson 133:98c6bf14bc37 46 tcp = "State Idle Protocol ARI Port-Loc Port-Rem Rcvd Sent\n";
andrewboyson 132:5b2df69a4f17 47 text.split('\n').forEach(parseTcpLine);
andrewboyson 132:5b2df69a4f17 48 }
andrewboyson 143:cc2e148cb96a 49 function parseDnsLine(line)
andrewboyson 143:cc2e148cb96a 50 {
andrewboyson 143:cc2e148cb96a 51 if (line.length == 0) return;
andrewboyson 143:cc2e148cb96a 52 let fields = line.split('\t');
andrewboyson 143:cc2e148cb96a 53
andrewboyson 143:cc2e148cb96a 54 dns += parseInt(fields[0], 16).toString().padStart(2, ' ');
andrewboyson 143:cc2e148cb96a 55 let minutes = parseInt(fields[1], 16) / 1000 / 60;
andrewboyson 143:cc2e148cb96a 56 dns += Math.floor(minutes).toString().padStart(4, ' ');
andrewboyson 143:cc2e148cb96a 57 dns += ' ';
andrewboyson 143:cc2e148cb96a 58 dns += Net.makeIp6(fields[2]).padEnd(40, ' ');
andrewboyson 143:cc2e148cb96a 59 dns += ' ';
andrewboyson 143:cc2e148cb96a 60 dns += fields[3];
andrewboyson 143:cc2e148cb96a 61 dns += ' ';
andrewboyson 143:cc2e148cb96a 62 dns += fields[4];
andrewboyson 143:cc2e148cb96a 63 dns += '\r\n';
andrewboyson 143:cc2e148cb96a 64 }
andrewboyson 144:7106252b7abf 65 function parseDnsLines(text)
andrewboyson 144:7106252b7abf 66 {
andrewboyson 144:7106252b7abf 67 dns = '';
andrewboyson 144:7106252b7abf 68 text.split('\n').forEach(parseDnsLine);
andrewboyson 144:7106252b7abf 69 }
andrewboyson 132:5b2df69a4f17 70 function parseGenLines(text)
andrewboyson 132:5b2df69a4f17 71 {
andrewboyson 132:5b2df69a4f17 72 let lines = text.split('\n');
andrewboyson 132:5b2df69a4f17 73 mac = Net.makeMac(lines[ 0]);
andrewboyson 132:5b2df69a4f17 74 }
andrewboyson 132:5b2df69a4f17 75 function parse()
andrewboyson 132:5b2df69a4f17 76 {
andrewboyson 132:5b2df69a4f17 77 let topics = Ajax.response.split('\f');
andrewboyson 132:5b2df69a4f17 78 parseGenLines(topics[0]);
andrewboyson 132:5b2df69a4f17 79 parseTcpLines(topics[1]);
andrewboyson 143:cc2e148cb96a 80 parseDnsLines(topics[2]);
andrewboyson 132:5b2df69a4f17 81 }
andrewboyson 132:5b2df69a4f17 82 function display()
andrewboyson 132:5b2df69a4f17 83 {
andrewboyson 132:5b2df69a4f17 84 let elem;
andrewboyson 132:5b2df69a4f17 85
andrewboyson 132:5b2df69a4f17 86 elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp;
andrewboyson 132:5b2df69a4f17 87 elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac;
andrewboyson 143:cc2e148cb96a 88 elem = Ajax.getElementOrNull('ajax-dns' ); if (elem) elem.textContent = dns;
andrewboyson 132:5b2df69a4f17 89 }
andrewboyson 132:5b2df69a4f17 90
andrewboyson 132:5b2df69a4f17 91 Ajax.server = '/net-ajax';
andrewboyson 132:5b2df69a4f17 92 Ajax.onResponse = function() { parse(); display(); };
andrewboyson 132:5b2df69a4f17 93 Ajax.init();