Searching for Linux command that can list all IP addresses of devices connected to the network?
Use nmap
or ping
commands to determine alive hosts in your local network.
[nmap] Scan Network for Alive Computers
Scan for active hosts on a network using nmap
command:
# Standard ICMP ping $ nmap -sn 192.168.1.0/24
Sample output:
Starting Nmap 6.00 ( http://nmap.org ) at 2013-06-14 00:52 EEST Nmap scan report for 192.168.1.1 Host is up (0.0031s latency). Nmap scan report for 192.168.1.101 Host is up (0.00097s latency). Nmap scan report for 192.168.1.102 Host is up (0.065s latency). Nmap done: 256 IP addresses (3 hosts up) scanned in 2.98 seconds
[ping] Find Active Hosts in LAN
Use the following script to find out what computers in your local network respond to ping
:
$ echo 192.168.1.{1..254}|xargs -n1 -P0 ping -c1|grep "bytes from"
Sample output:
64 bytes from 192.168.1.101: icmp_req=1 ttl=64 time=0.042 ms 64 bytes from 192.168.1.1: icmp_req=1 ttl=64 time=37.4 ms 64 bytes from 192.168.1.102: icmp_req=1 ttl=64 time=208 ms
Discover Computers Behind a Firewall
Some hosts may have a firewall, and will not respond to standard ICMP pings.
If a firewall is blocking standard ICMP pings, try the following host discovery methods:
# TCP SYN Ping $ nmap -sn -PS 192.168.1.0/24 # TCP ACK Ping $ nmap -sn -PA 192.168.1.0/24 # UDP Ping $ nmap -sn -PU 192.168.1.0/24 # IP Protocol Ping $ nmap -sn -PO 192.168.1.0/24 # ARP Ping $ nmap -sn -PR 192.168.1.0/24
Last three commands should be executed with root credentials.