Script to get Client Table from Router

Asked by tomdean

Ubuntu 14.04.

I have a Belkin wireless router and a mixture of computer systems connected to it, Linux, Windows, Android, etc.

To interact among the various computers, I have to use IP addresses, which to say the least is a PAIN!

I can connect to the router with a browser and get the DHCP client list. Looking at the source of this page, it is a java script.

I want to get the client list in a script. I want to get the name of all connected computers. Arp, nmap, host, etc. will not extract the hostnames.

Is this possible?

Tom Dean

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

Nmap will do it well.

Does your router not renew the same IP to the same name? Never seen a router not do that.... Weird.

Revision history for this message
tomdean (tomdean) said :
#2

On 06/19/14 15:16, actionparsnip wrote:
> Your question #250484 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/250484
>
> Status: Open => Answered
>
> actionparsnip proposed the following answer:
> Nmap will do it well.

Unless I, and several others, missed something, map will not return host
names!

Tom Dean

Revision history for this message
tomdean (tomdean) said :
#3

On 06/19/14 15:16, actionparsnip wrote:

> Does your router not renew the same IP to the same name? Never seen a
> router not do that.... Weird.
>

The router does allocate the same IP to the same name, the setting is
for leases to never expire, or, at least for a very long time.

Today, for example, there are two new computers on the network. They
will be here over the weekend.

To handle them, I used a browser, connected to the router, cut-paste the
client list into emacs and saved the file. Then, a script to update
etc/hosts. Copy the file to several machines and update etc/hosts.
Then, all is ready to go.

I do this several times a month.

Tom Dean

Revision history for this message
Best actionparsnip (andrew-woodhead666) said :
#4

sudo nmap −sP −R 192.168.0.0/24

May do it. You will need to install nmap

Revision history for this message
tomdean (tomdean) said :
#5

On 06/20/14 01:21, actionparsnip wrote:

> actionparsnip proposed the following answer:
> sudo nmap −sP −R 192.168.0.0/24

Thank you. Thank you. This helps a lot.

My version of nmap, uses -sn rather than -sP

 > nmap --version
Nmap version 6.40 ( http://nmap.org )
Platform: x86_64-pc-linux-gnu
Compiled with: liblua-5.2.3 openssl-1.0.1f libpcre-8.31 libpcap-1.5.3
nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select

Tom Dean

Revision history for this message
tomdean (tomdean) said :
#6

Thanks actionparsnip, that solved my question.

Revision history for this message
tomdean (tomdean) said :
#7

On 06/20/14 10:32, tomdean wrote:

Oopos. I forgot I had updated etc/hosts.

nmap reads the host names from etc/hosts, I believe.

With hostnames in etc/hosts:

 > nmap -sP -R 192.168.2.0/24
Starting Nmap 6.40 ( http://nmap.org ) at 2014-06-20 10:02 PDT
Nmap scan report for router.yyyyy (192.168.2.1)
Host is up (0.00057s latency).
Nmap scan report for android_xxxx (192.168.2.2)
Host is up (0.097s latency).
Nmap scan report for android_xxxx (192.168.2.5)
Host is up (0.10s latency).
Nmap scan report for P9X79.yyyyy (192.168.2.7)
Host is up (0.00013s latency).
Nmap scan report for android-xxxxx (192.168.2.8)
Host is up (0.15s latency).
Nmap scan report for android-xxxxx (192.168.2.9)
Host is up (0.19s latency).
Nmap scan report for zd7000.yyyyy (192.168.2.10)
Host is up (0.0022s latency).
Nmap done: 256 IP addresses (7 hosts up) scanned in 21.46 seconds

With NO hostnames in etc/hosts
 > nmap -sP -R 192.168.2.0/24
Starting Nmap 6.40 ( http://nmap.org ) at 2014-06-20 10:37 PDT
Nmap scan report for router.yyyyy (192.168.2.1)
Host is up (0.00056s latency).
Nmap scan report for 192.168.2.2
Host is up (0.10s latency).
Nmap scan report for 192.168.2.5
Host is up (0.099s latency).
Nmap scan report for 192.168.2.7
Host is up (0.00011s latency).
Nmap scan report for 192.168.2.8
Host is up (0.18s latency).
Nmap scan report for 192.168.2.9
Host is up (0.19s latency).
Nmap scan report for 192.168.2.10
Host is up (0.0013s latency).
Nmap done: 256 IP addresses (7 hosts up) scanned in 36.79 seconds