Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Revision:
88:2857259fc2b4
Parent:
86:f3c9beec4ee7
Child:
89:615fb951df69
--- a/net/http-net6-script.inc	Mon Apr 08 12:47:59 2019 +0000
+++ b/net/http-net6-script.inc	Wed Apr 10 10:06:14 2019 +0000
@@ -1,15 +1,93 @@
 "'use strict';\n"
 "\n"
-"var response     = '';\n"
-"var headers      = '';\n"
-"var arp          = '';\n"
-"var dns          = '';\n"
+"var response = '';\n"
+"var headers  = '';\n"
+"var arp      = '';\n"
+"var dns      = '';\n"
 "\n"
+"function makeIpWord(text)\n"
+"{\n"
+"    var word = parseInt(text, 16);\n"
+"    if (word === 0) return '';\n"
+"    return word.toString(16);\n"
+"}\n"
+"function makeIp(text)\n"
+"{\n"
+"    text = text.toLowerCase();\n"
+"    var result = '';\n"
+"    result += makeIpWord(text.substr( 0, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr( 4, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr( 8, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr(12, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr(16, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr(20, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr(24, 4));\n"
+"    result += ':';\n"
+"    result += makeIpWord(text.substr(28, 4));\n"
+"    return result;\n"
+"}\n"
+"function makeMac(text)\n"
+"{\n"
+"    text = text.toLowerCase();\n"
+"    var result = '';\n"
+"    result += text.substr( 0, 2);\n"
+"    result += ':';\n"
+"    result += text.substr( 2, 2);\n"
+"    result += ':';\n"
+"    result += text.substr( 4, 2);\n"
+"    result += ':';\n"
+"    result += text.substr( 6, 2);\n"
+"    result += ':';\n"
+"    result += text.substr( 8, 2);\n"
+"    result += ':';\n"
+"    result += text.substr(10, 2);\n"
+"    return result;\n"
+"}\n"
+"function parseArpLine(line)\n"
+"{\n"
+"    if (line.length == 0) return;\n"
+"    var minutes  = parseInt(line.substr(0, 8), 16) / 1000 / 60;\n"
+"    arp += Math.floor(minutes).toString().padStart(4, ' ');\n"
+"    arp += ' ';\n"
+"    arp += makeIp(line.substr(8, 32)).padEnd(40, ' ');\n"
+"    arp += ' ';\n"
+"    arp += makeMac(line.substr(40, 12));\n"
+"    arp += '\\r\\n';\n"
+"}\n"
+"function parseDnsLine(line)\n"
+"{\n"
+"    if (line.length == 0) return;\n"
+"    var minutes  = parseInt(line.substr(0, 8), 16) / 1000 / 60;\n"
+"    dns += Math.floor(minutes).toString().padStart(4, ' ');\n"
+"    dns += ' ';\n"
+"    dns += makeIp(line.substr(8, 32)).padEnd(40, ' ');\n"
+"    dns += ' ';\n"
+"    dns += line.substr(40, 1);\n"
+"    dns += ' ';\n"
+"    dns += line.substr(41);\n"
+"    dns += '\\r\\n';\n"
+"}\n"
+"function parseArpLines(text)\n"
+"{\n"
+"    arp = '';\n"
+"    text.split('\\n').forEach(parseArpLine);\n"
+"}\n"
+"function parseDnsLines(text)\n"
+"{\n"
+"    dns = '';\n"
+"    text.split('\\n').forEach(parseDnsLine);\n"
+"}\n"
 "function parseAjax()\n"
 "{\n"
 "    var topics = response.split('\\f');\n"
-"    arp = topics[0];\n"
-"    dns = topics[1];\n"
+"    parseArpLines(topics[0]);\n"
+"    parseDnsLines(topics[1]);\n"
 "}\n"
 "function displayGeneral()\n"
 "{\n"