List all devices connected to local network


/ Published in: Bash
Save to your folder(s)

Bash script to list all devices (ip and hostname) connected to your local network.
Some formatting is done, and a summary is printed at the end.
Requires nmap.


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. NETWORK="192.168.1.0/24"
  4. #Output formatting
  5. BOLD="\033[1m"
  6. WHITE_ON_GREY="\033[100;97m"
  7. RESET="\033[0m"
  8.  
  9. sudo nmap -sn -PO "$NETWORK" \
  10. | grep -oE "[a-zA-Z0-9\.\-]+\s\(([0-9]{1,3}\.){3}[0-9]{1,3}\)" \
  11. | sed 's/[)(]//g' \
  12. | awk -v bold="$BOLD" -v fg="$WHITE_ON_GREY" -v reset="$RESET" -f <(cat - <<-'EOD'
  13.   BEGIN{
  14.   OFS="\t";
  15.   }
  16.   { print $2,$1; }
  17.   END{
  18.   print bold fg NR" Hosts are up" reset;
  19.   }
  20. EOD
  21. )

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.