1

I wish to know the computer name associated with a known ip-address. The DNS is managed by my router (WIND3 webcube) and I can see the resolved name using the browser (http://192.168.1.1) Nevertheless, I wish to read the LAN computer names by command line from the console. I've tried <ping -r 192.168.1.255> then <arp -a> as suggested by Bodo; this has shown all IPs & relevant MACs on the LAN except my own; the only hostname shown has been the router name corresponding to 192.168.1.1 - half question has been answered, now I have a way to discover remote IPs on the LAN by console. In addition, using <nmap -sn 192.168.1.0/24>, I can see the full list of IPs on the LAN but still no hostnmes.

At the moment the best solution is running this script:
for x in {101..110}
do nslookup 192.168.1.$x | grep name
done

that shows all active names and relevant IPs (reversed)

  • 1
    see https://serverfault.com/q/7056 – Bodo Jan 16 '23 at 16:04
  • I suppose I badly explain what I need - sorry. I try to better explain. I know that the DHCP range is 192.168.1.100 ... 192.168.1.110 because I set it on the router . The best could be a command showing the list of IPaddr & hostname for each host connected, but it would also be acceptable a command for single enquiry i.e. IPaddr corresponding to an hostname or the reverse, hostname corresponding to an IPaddr. At the moment "dig -x " works for my own IPaddr and for DHCP server IPaddr only, giving my own hostname and the DHCP server's name. For all other IPaddr it returns blank names. – ClaudioKlaus Jan 18 '23 at 11:19
  • Please don't use comments to add information, [edit] your question instead. You might have to specify `@server`, see [man dig](https://linux.die.net/man/1/dig). I was not able to use `nslookup`'s `ls` or `dig`'s `axfr` to get a full listing from my router. Querying single addresses works. – Bodo Jan 18 '23 at 12:11

2 Answers2

2

workarounds(using ping, arp table and scans) that should work in most networks but might not report all devices(reports only those devices that echo/respond to the ping).

With ping and arp

ping(for a short while) the broadcast IP address(i.e. the highest, last and unusable IP address in your sub-net e.g. 192.168.1.255) which will in turn result in ping packets being sent to every possible IP address on your network like so:

ping -b 192.168.1.255

Then, run an arp(Address Resolution Protocol) request like so:

arp -a

With nmap

From man nmap:

-sn (No port scan)
  This option tells Nmap not to do a port scan after host discovery,
  and only print out the available hosts that responded to the host
  discovery probes. This is often known as a “ping scan”.

So, you can use it on your network like so:

nmap -sn 192.168.1.0/24

Where 192.168.1.0(the first unusable IP address i.e. 0) is your network address and 24 is your sub-net mask.

Raffa
  • 24,905
  • 3
  • 35
  • 79
1

To get the name for a single known IP address from the router you can use

dig @router -x ipaddress +short

for example

dig @192.168.1.1 -x 192.168.1.100 +short

see man dig

I was not able to use dig's query type axfr or nslookup's ls command to get a full listing from my router. This might be a permissions issue.

Of course you can use shell programming to run dig in a loop for a range of IP addresses.

Bodo
  • 338
  • 2
  • 10
  • You probably can do something like `seq -f "192.168.1.%g" 1 254 | xargs -n 1 dig @192.168.1.1 +noall +answer +time=1 -x` – Raffa Jan 19 '23 at 11:40