LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2018, 12:30 AM   #1
pgmer6809
LQ Newbie
 
Registered: Apr 2004
Distribution: Mint 21.1 Vera
Posts: 23

Rep: Reputation: 0
Query Router/DHCP Server for copu of its leases list


I know (from visiting its web admin pages) that my router/dhcp server maintains a list of hostnames to IP addresses. It preserves these even when the host in question is powered off.

This is a small (10-12 computers) local subnet that has no DNS server (it is not a windows domain), has mostly LINUX boxes (Netbios / samba server is not running on most of them) and has also a couple of cell phones, and a couple of MAC computers.
It is just big enough that trying to maintain a bunch of /etc/hosts files is a drag, and the dynamic IPs change just often enough that one can never be sure that what worked last week will work this week.

I would like to be able to access this information (IP addr <==> hostname pairs) from a script. Is there any cmd or piece of the DHCP protocol that can allow me to do that?

Please do NOT reply with any suggestions that involve DNS, WINS, /etc/hosts, or nbtscan.

I am also NOT asking how to find the ip address of the DHCP server, or my own hostname/IP address.

I mention all this negativity only because whenever this question (or a similar one) gets asked on the net, one of the above anwsers is invariably provided and they will not work in this case.

It seems to me that asking the DHCP server for a copy of the info it provides thru its web interface is the most efficient way to go.
Is this possible? (I could write something in Perl or Python if necessary. Or even in C)

Thanks,
pgmer6809
 
Old 09-15-2018, 06:39 AM   #2
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by pgmer6809 View Post
Is this possible? (I could write something in Perl or Python if necessary. Or even in C)

Thanks,
pgmer6809
Put simply, yes, it's possible. You could send an HTTP request to the page that would contain that information; log in, if needed; parse out the data you need.

Last edited by individual; 09-15-2018 at 06:41 AM. Reason: forgot a word.
 
Old 09-17-2018, 01:30 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,020

Rep: Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630
Knowing more about this router would help.

Routers for SOHO tend to allow leases based on some number of settings. One maybe to set leases permanent. Not sure why you'd play with hosts files unless you have already set either IP's to static or set leases to permanent. Any sort of less than forever lease would result in a chance of IP changing.

I guess if you can access this router via ssh then you may get info for something like this.

more /var/lib/dhcpd/dhcpd.leases
 
Old 09-19-2018, 06:07 PM   #4
pgmer6809
LQ Newbie
 
Registered: Apr 2004
Distribution: Mint 21.1 Vera
Posts: 23

Original Poster
Rep: Reputation: 0
Querying a router....

Thanks jefro. Good idea to use ssh or so if avail. I should have been thinking out of the box I guess.
I did run nmap to check on ports:
Code:
nmap -sV 192.168.1.254

Starting Nmap 7.60 ( https://nmap.org ) at 2018-09-18 23:52 PDT
Nmap scan report for _gateway (192.168.1.254)
Host is up (0.0054s latency).
Not shown: 992 closed ports
PORT     STATE    SERVICE      VERSION
20/tcp   filtered ftp-data
21/tcp   filtered ftp
22/tcp   filtered ssh
23/tcp   filtered telnet
80/tcp   open     http         micro_httpd
443/tcp  open     ssl/http     micro_httpd
5431/tcp open     upnp         Belkin/Linksys wireless router UPnP (UPnP 1.0; BRCM400 1.0)
9878/tcp open     kca-service?
Service Info: OS: Linux 2.4; Device: router; CPE: cpe:/o:linux:linux_kernel:2.4

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 150.40 seconds
and it looks like ssh is running.
But when I try to connect using say:
Code:
ssh 192.168.1.254 -l <priviledged-account>
it just hangs. Ditto if I use ssh loginname@192.168.1.254
Other attempts to use say telnet or ftp are also unsuccessful.
Any other good ideas?
pgmer6809
 
Old 09-19-2018, 06:19 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,748

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Quote:
Originally Posted by pgmer6809 View Post
Thanks jefro. Good idea to use ssh or so if avail. I should have been thinking out of the box I guess.
I did run nmap to check on ports:
Code:
nmap -sV 192.168.1.254

Starting Nmap 7.60 ( https://nmap.org ) at 2018-09-18 23:52 PDT
Nmap scan report for _gateway (192.168.1.254)
Host is up (0.0054s latency).
Not shown: 992 closed ports
PORT     STATE    SERVICE      VERSION
20/tcp   filtered ftp-data
21/tcp   filtered ftp
22/tcp   filtered ssh
23/tcp   filtered telnet
80/tcp   open     http         micro_httpd
443/tcp  open     ssl/http     micro_httpd
5431/tcp open     upnp         Belkin/Linksys wireless router UPnP (UPnP 1.0; BRCM400 1.0)
9878/tcp open     kca-service?
Service Info: OS: Linux 2.4; Device: router; CPE: cpe:/o:linux:linux_kernel:2.4

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 150.40 seconds
and it looks like ssh is running.
That result doesn’t say ssh is running. In fact it says port 22 is filtered.

What individual said...a script using wget, probably...

Last edited by scasey; 09-19-2018 at 06:20 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DHCP Server Out of Leases, But How? jlacroix Linux - Server 2 07-25-2012 08:12 AM
DHCP server and no free leases error zrnaqvi Linux - Networking 1 05-06-2010 11:10 AM
Wrote 0 leases to leases file - DHCP server lionel.rpm Linux - Server 3 07-22-2009 06:05 PM
DHCP SERVER ... no free leases!!!!! eder_michael11 Linux - General 2 04-25-2006 05:47 PM
DNS not resolving notes server name and dhcp not releasing leases DanielKwok Linux - Networking 1 02-10-2004 10:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration