Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
base/net/web-net4-script.js@110:8ab752842d25, 2019-04-30 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Apr 30 12:45:08 2019 +0000
- Revision:
- 110:8ab752842d25
- Parent:
- net/web-net4-script.js@103:91194cc19bbb
- Child:
- 136:be1d42268b5d
Tidied. About to rename to web.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 95:8c9dda8a0caf | 23 | let minutes = parseInt(line.substr(0, 8), 16) / 1000 / 60; |
| andrewboyson | 88:2857259fc2b4 | 24 | arp += Math.floor(minutes).toString().padStart(4, ' '); |
| andrewboyson | 88:2857259fc2b4 | 25 | arp += ' '; |
| andrewboyson | 96:eb2eb75bad0f | 26 | arp += Net.makeIp4(line.substr(8, 8)).padEnd(15, ' '); |
| andrewboyson | 88:2857259fc2b4 | 27 | arp += ' '; |
| andrewboyson | 96:eb2eb75bad0f | 28 | arp += Net.makeMac(line.substr(16, 12)); |
| andrewboyson | 88:2857259fc2b4 | 29 | arp += '\r\n'; |
| andrewboyson | 88:2857259fc2b4 | 30 | } |
| andrewboyson | 88:2857259fc2b4 | 31 | function parseDnsLine(line) |
| andrewboyson | 88:2857259fc2b4 | 32 | { |
| andrewboyson | 88:2857259fc2b4 | 33 | if (line.length == 0) return; |
| andrewboyson | 95:8c9dda8a0caf | 34 | let minutes = parseInt(line.substr(0, 8), 16) / 1000 / 60; |
| andrewboyson | 88:2857259fc2b4 | 35 | dns += Math.floor(minutes).toString().padStart(4, ' '); |
| andrewboyson | 88:2857259fc2b4 | 36 | dns += ' '; |
| andrewboyson | 96:eb2eb75bad0f | 37 | dns += Net.makeIp4(line.substr(8, 8)).padEnd(15, ' '); |
| andrewboyson | 88:2857259fc2b4 | 38 | dns += ' '; |
| andrewboyson | 88:2857259fc2b4 | 39 | dns += line.substr(16, 1); |
| andrewboyson | 88:2857259fc2b4 | 40 | dns += ' '; |
| andrewboyson | 88:2857259fc2b4 | 41 | dns += line.substr(17); |
| andrewboyson | 88:2857259fc2b4 | 42 | dns += '\r\n'; |
| andrewboyson | 88:2857259fc2b4 | 43 | } |
| andrewboyson | 88:2857259fc2b4 | 44 | function parseArpLines(text) |
| andrewboyson | 88:2857259fc2b4 | 45 | { |
| andrewboyson | 88:2857259fc2b4 | 46 | arp = ''; |
| andrewboyson | 88:2857259fc2b4 | 47 | text.split('\n').forEach(parseArpLine); |
| andrewboyson | 88:2857259fc2b4 | 48 | } |
| andrewboyson | 88:2857259fc2b4 | 49 | function parseDnsLines(text) |
| andrewboyson | 88:2857259fc2b4 | 50 | { |
| andrewboyson | 88:2857259fc2b4 | 51 | dns = ''; |
| andrewboyson | 88:2857259fc2b4 | 52 | text.split('\n').forEach(parseDnsLine); |
| andrewboyson | 88:2857259fc2b4 | 53 | } |
| andrewboyson | 89:615fb951df69 | 54 | function parseGenLines(text) |
| andrewboyson | 89:615fb951df69 | 55 | { |
| andrewboyson | 95:8c9dda8a0caf | 56 | let lines = text.split('\n'); |
| andrewboyson | 96:eb2eb75bad0f | 57 | localIp = Net.makeIp4(lines[ 0]) ; |
| andrewboyson | 96:eb2eb75bad0f | 58 | domainName = lines[ 1] ; |
| andrewboyson | 96:eb2eb75bad0f | 59 | hostName = lines[ 2] ; |
| andrewboyson | 96:eb2eb75bad0f | 60 | ntpIp = Net.makeIp4(lines[ 3]) ; |
| andrewboyson | 96:eb2eb75bad0f | 61 | dnsIp = Net.makeIp4(lines[ 4]) ; |
| andrewboyson | 96:eb2eb75bad0f | 62 | dhcpIp = Net.makeIp4(lines[ 5]) ; |
| andrewboyson | 96:eb2eb75bad0f | 63 | routerIp = Net.makeIp4(lines[ 6]) ; |
| andrewboyson | 96:eb2eb75bad0f | 64 | subnetMask = Net.makeIp4(lines[ 7]) ; |
| andrewboyson | 96:eb2eb75bad0f | 65 | broadcastIp = Net.makeIp4(lines[ 8]) ; |
| andrewboyson | 96:eb2eb75bad0f | 66 | leaseTime = parseInt(lines[ 9], 16); |
| andrewboyson | 96:eb2eb75bad0f | 67 | renewalT1 = parseInt(lines[10], 16); |
| andrewboyson | 96:eb2eb75bad0f | 68 | renewalt2 = parseInt(lines[11], 16); |
| andrewboyson | 96:eb2eb75bad0f | 69 | elapsed = parseInt(lines[12], 16); |
| andrewboyson | 89:615fb951df69 | 70 | } |
| andrewboyson | 95:8c9dda8a0caf | 71 | function parse() |
| andrewboyson | 86:f3c9beec4ee7 | 72 | { |
| andrewboyson | 95:8c9dda8a0caf | 73 | let topics = Ajax.response.split('\f'); |
| andrewboyson | 89:615fb951df69 | 74 | parseGenLines(topics[0]); |
| andrewboyson | 89:615fb951df69 | 75 | parseArpLines(topics[1]); |
| andrewboyson | 89:615fb951df69 | 76 | parseDnsLines(topics[2]); |
| andrewboyson | 86:f3c9beec4ee7 | 77 | } |
| andrewboyson | 95:8c9dda8a0caf | 78 | function display() |
| andrewboyson | 86:f3c9beec4ee7 | 79 | { |
| andrewboyson | 95:8c9dda8a0caf | 80 | let elem; |
| andrewboyson | 86:f3c9beec4ee7 | 81 | |
| andrewboyson | 95:8c9dda8a0caf | 82 | elem = Ajax.getElementOrNull('ajax-local-ip' ); if (elem) elem.textContent = localIp; |
| andrewboyson | 95:8c9dda8a0caf | 83 | elem = Ajax.getElementOrNull('ajax-domain-name' ); if (elem) elem.textContent = domainName; |
| andrewboyson | 95:8c9dda8a0caf | 84 | elem = Ajax.getElementOrNull('ajax-host-name' ); if (elem) elem.textContent = hostName; |
| andrewboyson | 95:8c9dda8a0caf | 85 | elem = Ajax.getElementOrNull('ajax-ntp-ip' ); if (elem) elem.textContent = ntpIp; |
| andrewboyson | 95:8c9dda8a0caf | 86 | elem = Ajax.getElementOrNull('ajax-dns-ip' ); if (elem) elem.textContent = dnsIp; |
| andrewboyson | 95:8c9dda8a0caf | 87 | elem = Ajax.getElementOrNull('ajax-dhcp-ip' ); if (elem) elem.textContent = dhcpIp; |
| andrewboyson | 95:8c9dda8a0caf | 88 | elem = Ajax.getElementOrNull('ajax-router-ip' ); if (elem) elem.textContent = routerIp; |
| andrewboyson | 95:8c9dda8a0caf | 89 | elem = Ajax.getElementOrNull('ajax-subnet-mask' ); if (elem) elem.textContent = subnetMask; |
| andrewboyson | 95:8c9dda8a0caf | 90 | elem = Ajax.getElementOrNull('ajax-broadcast-ip'); if (elem) elem.textContent = broadcastIp; |
| andrewboyson | 95:8c9dda8a0caf | 91 | elem = Ajax.getElementOrNull('ajax-lease-time' ); if (elem) elem.textContent = leaseTime; |
| andrewboyson | 95:8c9dda8a0caf | 92 | elem = Ajax.getElementOrNull('ajax-renewal-t1' ); if (elem) elem.textContent = renewalT1; |
| andrewboyson | 95:8c9dda8a0caf | 93 | elem = Ajax.getElementOrNull('ajax-renewal-t2' ); if (elem) elem.textContent = renewalt2; |
| andrewboyson | 95:8c9dda8a0caf | 94 | elem = Ajax.getElementOrNull('ajax-elapsed' ); if (elem) elem.textContent = elapsed; |
| andrewboyson | 95:8c9dda8a0caf | 95 | elem = Ajax.getElementOrNull('ajax-arp' ); if (elem) elem.textContent = arp; |
| andrewboyson | 95:8c9dda8a0caf | 96 | elem = Ajax.getElementOrNull('ajax-dns' ); if (elem) elem.textContent = dns; |
| andrewboyson | 86:f3c9beec4ee7 | 97 | } |
| andrewboyson | 86:f3c9beec4ee7 | 98 | |
| andrewboyson | 95:8c9dda8a0caf | 99 | Ajax.server = '/net4-ajax'; |
| andrewboyson | 95:8c9dda8a0caf | 100 | Ajax.onResponse = function() { parse(); display(); }; |
| andrewboyson | 95:8c9dda8a0caf | 101 | Ajax.init(); |