nmap -v -sn 192.168.10/25 -oG - | awk '/Up$/{print $2}'
nmap: The network mapper tool, used for scanning hosts and networks.
-v: Enables verbose output, giving more detail during the scan.
-sn: Stands for "ping scan" — it disables port scanning and only checks which hosts are up (i.e., responding to ping or ARP).
192.168.10.0/25: This is a CIDR subnet notation. It scans IPs from 192.168.10.0 to 192.168.10.127 — a total of 128 addresses.
-oG -: Outputs results in grepable format (-oG) and sends it to stdout (-), rather than a file.
nmap -v -sn 192.168.10.0/25 -oG - | awk '/Up$/{print $2}' | while read ip; do echo -n "$ip "; nslookup "$ip" | awk '/name =/{print $4}'; done
while read ip; do ... done: Loops through each IP found to be up.
nslookup "$ip": Resolves the hostname for each IP.
awk '/name =/{print $4}': Extracts the canonical hostname from nslookup output.
bash function