Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /var/bin/mksh
- # grab just the ip address from ping output, then sort|uniq
- set -A uniquehosts $(ping -nc 3 broadcast | sed -n '/icmp_seq=/{
- s/^[0-9]* bytes from //
- s/: icmp_seq=.*$//
- p
- }' | sort | uniq )
- # for each ip, lookup hostname from /etc/hosts
- for host in ${uniquehosts[@]}
- do
- hostname=$(awk \/^${host}'[ \t]/{ print $2 }' /etc/hosts )
- if [[ -z $hostname ]]; then
- echo $host
- else
- echo $hostname
- fi
- done
Add Comment
Please, Sign In to add comment