9

I wanted to know all the devices name 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 name 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 name of all devices connected to my wifi network via commandline.

Thanks


Example:


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
7
+50

I tend to use fing 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.

Ex:

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.

  • How do you install fing? Your link is dead and it is not included in any of the Raspberry Pi repositories. – Patrick Cook Apr 16 '16 at 14:20
  • Hi Patrick. It seems they moved to a new domain and did not bother setting up redirection from the old one. Fixed the link to point to the new domain. – Jake Apr 16 '16 at 17:26
  • 3
    Please state how you called fing to obtain that output. Without the command, the answer is incomplete. – user666412 Sep 4 '17 at 15:56
  • 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 '17 at 14:30
  • 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. – Sopalajo de Arrierez Feb 2 '18 at 18:50
5

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.

5

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.

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/)

  • Ciao Simone! This only works for windows hosts, but i need to discover every device name on my network. – Federico Ponzi Mar 5 '15 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 '15 at 17:27
1

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.

  • This can only resolve NetBIOS names. – Pierz Apr 12 '17 at 15:13
  • And, for my tests, it seems not showing all the NetBIOS names in the network. – Sopalajo de Arrierez Feb 2 '18 at 18:59
-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.

-2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.