You are here

Getting a complete node list

9 posts / 0 new
Last post
Getting a complete node list
I would like to periodically grab a list of all nodes on the mesh with IP Address and host name. Basically, the first two columns of the Topology Entries section from http://localnode.local.mesh:1978/nodes, sorted for unique entries.  The IP Addresses are available from http://localnode.local.mesh:2006/topo, but not the host names.  I know I can loop through this list and get the host names through several means. But, it would be nice to get this in one simple grab.

So, does anyone know a way to do this, or maybe has already got a script for it?

BTW, my application is to maintain a list of hosts and the last time they were seen.

K5DLQ's picture
PERFECT.  Thanks.

Example code
As noted above, the link provided by Darryl delivers the requested information, and more... One problem I have identified is the host list returned from the node includes all hosts, other than those associated with services. This problem is one identified previously: If a host is assigned a static DHCP address, it will appear in the routing table -if it does not have a service associated with it, it cannot be differentiated from a node.  In our case, all real node names begin with a call-sign, other hostnames don't. So, I can key on that to cull out the non-node entries. However, hopefully once there is a way to mark a DHCP address reservation as "non-published" the problem should dissapear.

For anyone interested in this discussion, here is a snippet of Python code to grab the node names and addresses from the json output:

import urllib2
import json

nodeAddr = "wb6tae-1998"  # put the name or address oif your node here
url = 'http://' + nodeAddr + ':8080/cgi-bin/sysinfo.json?hosts=1'

response = urllib2.urlopen(url)
decoded_response ="UTF-8")

jsonResponse = json.loads(decoded_response)
jsonData = jsonResponse["hosts"]

for item in jsonData:
    hostname = item.get("name", "Null")
    ipaddr = item.get("ip", "Null")
    print("%-28s %-16s" % (hostname, ipaddr))

K5DLQ's picture
you could use:
you could use:

that will resolve to the node that you are connected directly to.
Yes... that would be the best
Yes... that would be the best. Unfortunately I have a small DNS issue here on a new computer and for some reason that has been unreliable. But, the host name I used in the code is the localnode anyway.  
K5DLQ's picture
You may want to make sure
You may want to make sure that you use <NODE>.local.mesh as well.
Now don't be too picky...

Now don't be too picky... this was just a snippet for demo sake. The main point is how to get the json data and extract the needed elements.
But, yes that would be a good idea. In my case, I have .local.mesh in my dns search string so I don't have to worry about including a full domain name.

Get all LAN IPs

The script above using the json info all looks good except I want the node router LAN ip.  Is there a way to get that?  
I don't need the device WIFI address.

In the end I'll do a sort: sort -t . -k 2,3n -k 4,4n
The idea is to show all the hosts and node devices grouped together by LAN addresses.

- Mike

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer