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-net-script.inc@133:98c6bf14bc37, 2020-03-11 (annotated)
- Committer:
- andrewboyson
- Date:
- Wed Mar 11 16:00:21 2020 +0000
- Revision:
- 133:98c6bf14bc37
- Parent:
- 132:5b2df69a4f17
- Child:
- 143:cc2e148cb96a
Addewd more fields to TCP connections
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 132:5b2df69a4f17 | 1 | "//Net script\n" |
andrewboyson | 132:5b2df69a4f17 | 2 | "'use strict';\n" |
andrewboyson | 132:5b2df69a4f17 | 3 | "\n" |
andrewboyson | 132:5b2df69a4f17 | 4 | "let mac = '';\n" |
andrewboyson | 132:5b2df69a4f17 | 5 | "let tcp = '';\n" |
andrewboyson | 132:5b2df69a4f17 | 6 | "\n" |
andrewboyson | 132:5b2df69a4f17 | 7 | "function parseTcpLine(line)\n" |
andrewboyson | 132:5b2df69a4f17 | 8 | "{\n" |
andrewboyson | 132:5b2df69a4f17 | 9 | " if (line.length == 0) return;\n" |
andrewboyson | 132:5b2df69a4f17 | 10 | " let fields = line.split('\\t');\n" |
andrewboyson | 133:98c6bf14bc37 | 11 | " let state = parseInt(fields[0], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 12 | " let idleMs = parseInt(fields[1], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 13 | " let ipType = parseInt(fields[2], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 14 | " let arIndex = parseInt(fields[3], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 15 | " let locPort = parseInt(fields[4], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 16 | " let remPort = parseInt(fields[5], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 17 | " let bytesRcvd = parseInt(fields[6], 16);\n" |
andrewboyson | 133:98c6bf14bc37 | 18 | " let bytesSent = parseInt(fields[7], 16);\n" |
andrewboyson | 132:5b2df69a4f17 | 19 | " \n" |
andrewboyson | 133:98c6bf14bc37 | 20 | " switch (state)\n" |
andrewboyson | 133:98c6bf14bc37 | 21 | " {\n" |
andrewboyson | 133:98c6bf14bc37 | 22 | " case 1: tcp += \" Syn\"; break;\n" |
andrewboyson | 133:98c6bf14bc37 | 23 | " case 2: tcp += \" Est\"; break;\n" |
andrewboyson | 133:98c6bf14bc37 | 24 | " case 3: tcp += \" Wait\"; break;\n" |
andrewboyson | 133:98c6bf14bc37 | 25 | " default: tcp += state.toString().padStart(5, ' '); break;\n" |
andrewboyson | 133:98c6bf14bc37 | 26 | " }\n" |
andrewboyson | 132:5b2df69a4f17 | 27 | " \n" |
andrewboyson | 133:98c6bf14bc37 | 28 | " let idleMinutes = Math.floor(idleMs / 1000 / 60);\n" |
andrewboyson | 133:98c6bf14bc37 | 29 | " tcp += idleMinutes.toString().padStart(4, ' ');\n" |
andrewboyson | 133:98c6bf14bc37 | 30 | " tcp += \" \";\n" |
andrewboyson | 132:5b2df69a4f17 | 31 | " \n" |
andrewboyson | 133:98c6bf14bc37 | 32 | " if (ipType == 0x0800) tcp += \"IPv4\";\n" |
andrewboyson | 132:5b2df69a4f17 | 33 | " else if (ipType == 0x86DD) tcp += \"IPv6\";\n" |
andrewboyson | 132:5b2df69a4f17 | 34 | " else tcp += fields[1];\n" |
andrewboyson | 132:5b2df69a4f17 | 35 | " \n" |
andrewboyson | 133:98c6bf14bc37 | 36 | " tcp += arIndex.toString().padStart(4, ' ');\n" |
andrewboyson | 133:98c6bf14bc37 | 37 | " tcp += locPort.toString().padStart(9, ' ');\n" |
andrewboyson | 133:98c6bf14bc37 | 38 | " tcp += remPort.toString().padStart(9, ' ');\n" |
andrewboyson | 133:98c6bf14bc37 | 39 | " tcp += bytesRcvd.toString().padStart(6, ' ');\n" |
andrewboyson | 133:98c6bf14bc37 | 40 | " tcp += bytesSent.toString().padStart(6, ' ');\n" |
andrewboyson | 132:5b2df69a4f17 | 41 | " tcp += '\\r\\n';\n" |
andrewboyson | 132:5b2df69a4f17 | 42 | "}\n" |
andrewboyson | 132:5b2df69a4f17 | 43 | "function parseTcpLines(text)\n" |
andrewboyson | 132:5b2df69a4f17 | 44 | "{\n" |
andrewboyson | 133:98c6bf14bc37 | 45 | " tcp = \"State Idle Protocol ARI Port-Loc Port-Rem Rcvd Sent\\n\";\n" |
andrewboyson | 132:5b2df69a4f17 | 46 | " text.split('\\n').forEach(parseTcpLine);\n" |
andrewboyson | 132:5b2df69a4f17 | 47 | "}\n" |
andrewboyson | 132:5b2df69a4f17 | 48 | "function parseGenLines(text)\n" |
andrewboyson | 132:5b2df69a4f17 | 49 | "{\n" |
andrewboyson | 132:5b2df69a4f17 | 50 | " let lines = text.split('\\n');\n" |
andrewboyson | 132:5b2df69a4f17 | 51 | " mac = Net.makeMac(lines[ 0]);\n" |
andrewboyson | 132:5b2df69a4f17 | 52 | "}\n" |
andrewboyson | 132:5b2df69a4f17 | 53 | "function parse()\n" |
andrewboyson | 132:5b2df69a4f17 | 54 | "{\n" |
andrewboyson | 132:5b2df69a4f17 | 55 | " let topics = Ajax.response.split('\\f');\n" |
andrewboyson | 132:5b2df69a4f17 | 56 | " parseGenLines(topics[0]);\n" |
andrewboyson | 132:5b2df69a4f17 | 57 | " parseTcpLines(topics[1]);\n" |
andrewboyson | 132:5b2df69a4f17 | 58 | "}\n" |
andrewboyson | 132:5b2df69a4f17 | 59 | "function display()\n" |
andrewboyson | 132:5b2df69a4f17 | 60 | "{\n" |
andrewboyson | 132:5b2df69a4f17 | 61 | " let elem;\n" |
andrewboyson | 132:5b2df69a4f17 | 62 | "\n" |
andrewboyson | 132:5b2df69a4f17 | 63 | " elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp;\n" |
andrewboyson | 132:5b2df69a4f17 | 64 | " elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac;\n" |
andrewboyson | 132:5b2df69a4f17 | 65 | "}\n" |
andrewboyson | 132:5b2df69a4f17 | 66 | "\n" |
andrewboyson | 132:5b2df69a4f17 | 67 | "Ajax.server = '/net-ajax';\n" |
andrewboyson | 132:5b2df69a4f17 | 68 | "Ajax.onResponse = function() { parse(); display(); };\n" |
andrewboyson | 132:5b2df69a4f17 | 69 | "Ajax.init();\n" |
andrewboyson | 132:5b2df69a4f17 | 70 | "" |