35

I wanted to know the names of all the devices on the network. I've already tried without great success many commands found on the web, but nothing worked like I wanted to.

Basically, when I enter my router settings, I can get the devices' names that are connected to my net. I can get it also on some applications so I guess it can be done in some way.

I want a list of names of all devices connected to my Wi-Fi network via the commandline.

Thanks


pi@raspberrypi ~ $ nmap -sP 192.168.4.0/24

Starting Nmap 6.00 ( http://nmap.org ) at 2015-03-05 13:55 UTC
Nmap scan report for 192.168.4.1
Host is up (0.0055s latency).
Nmap scan report for 192.168.4.2
Host is up (0.42s latency).
Nmap scan report for 192.168.4.4
Host is up (0.045s latency).
Nmap scan report for 192.168.4.5
Host is up (0.47s latency).
Nmap scan report for 192.168.4.6
Host is up (0.0032s latency).
Nmap scan report for 192.168.4.7
Host is up (0.79s latency).
Nmap scan report for 192.168.4.8
Host is up (0.0024s latency).
Nmap scan report for 192.168.4.9
Host is up (0.038s latency).
Nmap scan report for 192.168.4.10
Host is up (0.034s latency).
Nmap scan report for 192.168.4.11
Host is up (0.029s latency).
Nmap scan report for 192.168.4.22
Host is up (0.12s latency).
Nmap scan report for 192.168.4.27
Host is up (0.031s latency).
Nmap scan report for 192.168.4.28
Host is up (0.012s latency).
Nmap scan report for 192.168.4.100
Host is up (0.0038s latency).
Nmap done: 256 IP addresses (14 hosts up) scanned in 49.30 seconds
1

9 Answers 9

23

None of the above answers worked for me, so I began messing around with arp-scan. So, what I found worked was:

arp-scan -I [WIFI INTERFACE] -l

arp-scan scans your network and lists devices. -I selects the interface, and -l tells arp-scan to look at the local network. Next, type

arp

This will return the devices arp-scan just located, and will list their hostnames and MAC addresses.

1
  • Some devices are reported as "(Unknown: locally administered)". How to solve it? Feb 14 at 3:39
13

I think you need to be more precise about your problem, especially the definition of a device name.

Unfortunately I don't have access to a Raspberry Pi at the moment, so everything displayed here comes from my Debian 7 box.

nmap -sP does reverse DNS lookups, so if your devices have reverse DNS entries, its output looks like this:

> nmap -sP 192.168.4.0/24
Starting Nmap 6.00 ( http://nmap.org ) at 2015-03-12 06:24 CET
Nmap scan report for device1.local (192.168.4.1)
Host is up (0.0021s latency).
Nmap scan report for device2.local (192.168.4.2)
Host is up (0.014s latency).
…

Hosts that block ping probes will not appear in the output. Nor will any hosts that don't offer services on the ports that you scan using the -p option. Scanning the whole port range with -p 0-65535, while generating a significant network footprint, will still not show hosts that simply don't have any open ports.

The only reliable information that you have about hosts in your network is that they have MAC and IP addresses. Your DHCP server knows both of them since it has assigned the IP addresses. Additionally, many DHCP clients send a host-name included in their DHCP request, so the DHCP server has a name for this device, even if that name does not appear anywhere else (DNS, SMB, …).

Unfortunately your DHCP server does not seem to report the dynamically assigned IP addresses to your name server so you cannot retrieve this information.

To find all devices within your network, you can dump the ARP table after pinging all hosts (e.g. using nmap -sP):

> arp -vn
Address               HWtype  HWaddress           Flags Mask            Iface
192.168.4.1           ether   12:34:56:78:9a:bc   C                     wlan0
192.168.4.2           ether   11:22:33:44:55:66   C                     wlan0
…

With MAC and IP addresses you have the only consistent information about your network neighborhood. Probing for an open port 445 will show you devices that are most likely supporting SMB (i.e. Windows network) — and thus have a windows name.

Connecting to other open ports (e.g. 21/ftp, 22/ssh, 23/telnet, …) may also offer the hostnames, but always in a protocol dependent way — and the hosts may theoretically call themselves differently on all ports.

Alternatively you could set up your own DHCP and DNS server on the Pi and provide a working reverse DNS service.

If all your devices support Zeroconf, you might be able to do a device discovery this way.

12
+50

I tend to use fing-cli from fing development toolkit for this. It is a scanner that scans the subnet you are on and it tries to extract hostnames and display them alongside ip and MAC.

You should install it manually from the site, or with your package manager (brew install fing-cli) and run with administrator privileges to make it work.

Ex:

sudo fing
14:19:05 > Discovery profile: Default discovery profile
14:19:05 > Discovery class:   data-link (data-link layer)
14:19:05 > Discovery on:      192.168.1.0/24

14:19:05 > Discovery round starting.
14:19:05 > Host is up:   192.168.1.151
           HW Address:   XX:XX:XX:XX:XX:XX
           Hostname:     My-laptop-hostname

14:19:05 > Host is up:   192.168.1.1
           HW Address:   YY:YY:YY:YY:YY:YY
           Hostname:     router.asus.com

14:19:06 > Discovery progress 25%
14:19:07 > Discovery progress 50%
14:19:08 > Discovery progress 75%
14:19:05 > Host is up:   192.168.1.10
           HW Address:   AA:BB:CC:DD:EE:FF (ASUSTek COMPUTER)

14:19:05 > Host is up:   192.168.1.11
           HW Address:   GG:HH:II:JJ:KK:LL

14:19:06 > Host is up:   192.168.1.99
           HW Address:   MM:NN:OO:PP:QQ:RR (Apple)
           Hostname:     iPhoneOfSomeone

As you can see not all devices give out their hostname; for example some peripherals like printers do not always provide hostnames, but most devices do. It even tries to guess the manufacturer by analysing the id-part of the MAC

It runs on the Raspberry Pi, i installed it on mine a while ago and it works as expected.

7
  • 2
    How do you install fing? Your link is dead and it is not included in any of the Raspberry Pi repositories. Apr 16, 2016 at 14:20
  • 9
    Please state how you called fing to obtain that output. Without the command, the answer is incomplete.
    – user666412
    Sep 4, 2017 at 15:56
  • 2
    I used a apt-get install libpcap-dev ; wget https://www.fing.io/wp-content/uploads/2016/10/overlook-fing-3.0.deb ; dpkg -i overlook-fing-3.0.deb to install, then fing to run it. It didn't report a hostname for my Rpi, but did recognize it as HW Address: B8:27:EB:1B:E6:0C (Raspberry Pi Foundation).
    – Dave X
    Dec 10, 2017 at 14:30
  • 2
    Not even one hostname detected on a 22 devices network on a first test network. Same with another 24 hosts. Fing, as for now (Febr 2018) seems to me a mess. Feb 2, 2018 at 18:50
  • 7
    Is the link still correct? It appears to be an IoT product rather than a command-line tool now.
    – Venryx
    Mar 22, 2019 at 8:18
10

Three answers here refer to nmap but I found prefixing sudo (which none of the answers do) makes all the difference in the world:

$ nmap -sP 192.168.1.0/24

Starting Nmap 7.01 ( https://nmap.org ) at 2019-07-13 14:55 MDT
Nmap scan report for 192.168.1.65
Host is up (0.00037s latency).
Nmap scan report for 192.168.1.66
Host is up (0.00035s latency).
Nmap scan report for 192.168.1.67
Host is up (0.00028s latency).
Nmap scan report for 192.168.1.68
Host is up (0.00025s latency).
Nmap scan report for 192.168.1.70
Host is up (0.017s latency).
Nmap scan report for 192.168.1.254
Host is up (0.00070s latency).
Nmap done: 256 IP addresses (6 hosts up) scanned in 6.86 seconds

$ sudo nmap -sP 192.168.1.0/24

Starting Nmap 7.01 ( https://nmap.org ) at 2019-07-13 14:56 MDT
Nmap scan report for 192.168.1.65
Host is up (0.00050s latency).
MAC Address: 99:99:99:99:99:A6 (Unknown)
Nmap scan report for 192.168.1.66
Host is up (0.00016s latency).
MAC Address: 99:99:99:99:99:D9 (Sony)
Nmap scan report for 192.168.1.70
Host is up (-0.087s latency).
MAC Address: 99:99:99:99:99:36 (Unknown)
Nmap scan report for 192.168.1.254
Host is up (0.0020s latency).
MAC Address: 99:99:99:99:99:00 (Actiontec Electronics)
Nmap scan report for 192.168.1.67
Host is up.
Nmap scan report for 192.168.1.68
Host is up.
Nmap done: 256 IP addresses (6 hosts up) scanned in 2.41 seconds

I stumbled upon this Q&A because I'm researching a project on how to display Human readable names rather than computer coded IP addresses and MAC addresses to devices.

In particular I want "Toshiba 43" 4K TV" to displayed rather than "(unknown)" for MAC 99:99:99:99:99:36 (not real address) above.

Later I want expand the project past the Local Area Network to the Internet where "Stack Exchange" will display instead of 999.999.9.99 or "Ask Ubuntu" will display instead of 999.999.9.99 when I'm looking at external IP addresses my machine is interacting with.

1
  • Using sudo really does give a lot more information, I wish other discussions talked about this.
    – lunarfyre
    May 31, 2021 at 21:52
5

avahi-browse -alr provides this information for other devices in the local network on which avahi-daemon is running.

3

In order to get the device name of Windows hosts, use

nmap --script smb-os-discovery -p 445 192.168.1.0/24

(source: http://www.blackbytes.info/2013/07/finding-windows-host/)

2
  • Ciao Simone! This only works for windows hosts, but i need to discover every device name on my network. Mar 5, 2015 at 14:35
  • 1
    I may be wrong, but I'm not sure what the concept of "device name" would be for a Linux machine. The closest thing I can think of is the host name defined in /etc/HOSTNAME or /etc/hostname, but I don't know if you can get it by asking the machine (unless, of course, a DNS server provides it).
    – rand
    Mar 5, 2015 at 17:27
2

On Linux, you can use nbtscan to achieve what you seek.

Run sudo apt-get install nbtscan to install.

To view the device hostnames connected to your network,

run sudo nbtscan 192.168.0.1-192.168.0.255,

assuming the host is at 192.168.0.1 and uses a subnet mask of 255.255.255.0. Adjust the IP range according to your network configuration.

2
  • This can only resolve NetBIOS names.
    – Pierz
    Apr 12, 2017 at 15:13
  • And, for my tests, it seems not showing all the NetBIOS names in the network. Feb 2, 2018 at 18:59
-1

You need nmap. Issue a command like:

nmap -sP 192.168.1.0/24

and it will do a network discovery on the subnet 192.168.1.0 - 192.168.1.255 showing you names and IP addresses of all devices on that network.

0
-1

jcbermu is very close, but from nmap's man page:

-sL (List Scan) .
       The list scan is a degenerate form of host discovery that simply lists each host of the network(s) specified, without sending any packets to the target hosts. By default, Nmap still does
       reverse-DNS resolution on the hosts to learn their names.

If it is stored in an rDNS entry this will find it, otherwise you might have to listen for DHCP requests and intercept them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .