Get computer list on Westell ATT 755 router

Final edit: Made into subflow, with 1 input and 2 outputs.

Edit: Changed Gist to Public. This is for Node-Red, found on http://nodered.org

This flow retrieves the computer list found on ATT's stock router, http://www.amazon.com/Westell-7550-DSL-Modem-Router/dp/B008SBUSHI . (apologies for the amazon link)

Reasoning: I wanted to retrieve all computers on the router, so that I can make logic that does things when X MAC address is on network, or when the device isn't. The premise was to do things like "turn on/off lights when I leave".

Implementation: The flow has 1 input and 2 outputs. You will need to hook up a trigger on the input to start the router query. It can be an empty packet. The 2 outputs are for IPv4 and IPv6. The first (or upper) port is IPv4. The lower (or 2nd) port is for IPv6.

The result is an array of the appropriate IPv[4-6] list of machines on the nework. They output as an array.

I changed this from outputting a single msg per machine, as that way was hard to detect a machine not on the network. Now, one can simply iterate through the array to find the machine, or not.

---This script requires the optional component node-red-contrib-splitter for splitting the 2 dimensional array (list of computer details inside an array of computers). Splitter outputs a msg for each outer array element.

Splitter is no longer a requirement for this flow.

[{"id":"f035f74e.e9f45","type":"subflow","name":"Westell router machine query","in":[{"x":37,"y":137,"wires":[{"id":"72903e3e.0b274"}]}],"out":[{"x":676,"y":192,"wires":[{"id":"4ae0ca04.daccfc","port":0}]},{"x":678,"y":252,"wires":[{"id":"4ae0ca04.daccfc","port":1}]}]},{"id":"72903e3e.0b274","type":"http request","name":"","method":"GET","ret":"txt","url":"http://192.168.1.254/html/statistics.asp?showAdvance=4","x":161,"y":137,"z":"f035f74e.e9f45","wires":[["d0e20a2a.b06838"]]},{"id":"d0e20a2a.b06838","type":"function","name":"HTML Filter","func":"// \"Devices on LAN\" was the keyword used to indicate the pertinent block of computers\nvar indexToEnd = msg.payload.substring(msg.payload.search(\"Devices on LAN\"), msg.payload.length );\n// \"Ethernet\" was at the end of said page as well. I started searching for this AFTER \"Devices on LAN\"\nvar endIndex = indexToEnd.search(\"Ethernet\");\n// Saves the important chunk of text into msg.payload\nmsg.payload = indexToEnd.substring(0,endIndex);\n\nmsg.payload = msg.payload.replace(/<\\/span>/g, \" \");\nmsg.payload = msg.payload.replace(/<span class=\\\"bf\\\">/g, \" \");\nmsg.payload = msg.payload.replace(/<span class=\\\"font2\\\">/g, \" \");\nmsg.payload = msg.payload.replace(/&nbsp/g, \" \");\nmsg.payload = msg.payload.replace(/<BR>/g, \" \");\nmsg.payload = msg.payload.replace(\"<table cellPadding=\\\"1\\\" width=\\\"450\\\" border=\\\"01\\\">\", \" \");\nmsg.payload = msg.payload.replace(/<\\/table>/g, \" \");\nmsg.payload = msg.payload.replace(/<tr>/g, \" \");\nmsg.payload = msg.payload.replace(/<td>/g, \" \");\n\nmsg.payload = msg.payload.replace(/<td width=\\\"100\\\">/g, \" \");\nmsg.payload = msg.payload.replace(/<td width=\\\"150\\\">/g, \" \");\nmsg.payload = msg.payload.replace(/<\\/td>/g, \" \");\nmsg.payload = msg.payload.replace(/<\\/tr>/g, \" \");\n\nmsg.payload = msg.payload.replace(/Devices on LAN/g, \" \");\nmsg.payload = msg.payload.replace(/IP Address/g, \" \");\nmsg.payload = msg.payload.replace(/MAC Address/g, \" \");\nmsg.payload = msg.payload.replace(/Name/g, \" \");\nmsg.payload = msg.payload.replace(/Status/g, \" \");\nmsg.payload = msg.payload.replace(/\\r?\\n|\\r/g, \" \");\n\nmsg.payload = msg.payload.replace(/ /g, \"\");\n\n// Outputs an array of computer details\nmsg.payload = msg.payload.split(\";\");\n\nreturn msg;","outputs":1,"noerr":0,"x":346,"y":136,"z":"f035f74e.e9f45","wires":[["180e85c2.8fef22"]]},{"id":"180e85c2.8fef22","type":"function","name":"array maker","func":"// Creates an array the side of how many computers there are.\nvar computerList = [ (msg.payload.length-msg.payload.length%4)/4 ];\n// Iterates through computerList and assigns the respective data\nfor (i=0; i<(msg.payload.length-msg.payload.length%4)/4; i++){\n  computerList[i]=[ msg.payload[4*i],msg.payload[(4*i)+1],msg.payload[(4*i)+2],msg.payload[(4*i)+3] ];\n}\n\nmsg.payload = computerList;\nreturn msg;","outputs":1,"noerr":0,"x":513,"y":136,"z":"f035f74e.e9f45","wires":[["4ae0ca04.daccfc"]]},{"id":"4ae0ca04.daccfc","type":"function","name":"","func":"var ipv4 = [];\nvar ipv6 = [];\n\nfor(var i = 0; i < msg.payload.length; i++){\n    if( msg.payload[i][0].indexOf(\".\")>=0 ){\n        ipv4.push(msg.payload[i]);\n    }\n    else{\n        ipv6.push(msg.payload[i]);\n    }\n}\nvar msg2 = {payload: msg.payload};\nmsg.payload = ipv4;\nmsg2.payload = ipv6;\n\nreturn [msg, msg2];\n","outputs":"2","noerr":0,"x":553,"y":215,"z":"f035f74e.e9f45","wires":[[],[]]},{"id":"45451efa.deea2","type":"subflow:f035f74e.e9f45","name":"","x":345,"y":185,"z":"cd5bb07f.ad4118","wires":[["e952df00.48508"],["56ea41e2.fa5ca8"]]}]

Flow Info

Created 9 years, 3 months ago
Updated 9 years, 1 month ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • function (x3)
  • http request (x1)
Other
  • subflow (x1)
  • subflow:f035f74e.e9f45 (x1)

Tags

  • Router
  • MAC
  • splitter
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option