shiftdot515

alive

Oct 18th, 2017
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.44 KB | None | 0 0
  1. #! /var/bin/mksh
  2. # grab just the ip address from ping output, then sort|uniq
  3. set -A uniquehosts $(ping -nc 3 broadcast | sed -n '/icmp_seq=/{
  4. s/^[0-9]* bytes from //
  5. s/: icmp_seq=.*$//
  6. p
  7. }' | sort | uniq )
  8. # for each ip, lookup hostname from /etc/hosts
  9. for host in  ${uniquehosts[@]}
  10. do
  11.   hostname=$(awk \/^${host}'[ \t]/{ print $2 }' /etc/hosts )
  12.   if [[ -z $hostname ]]; then
  13.    echo $host
  14.   else
  15.    echo $hostname
  16.   fi
  17. done
Add Comment
Please, Sign In to add comment