On 12/02/2010 06:15 PM, John Andersen wrote:
On 12/2/2010 3:37 PM, David C. Rankin wrote:
Guys,
What would I use to get a list of hosts on the local subnet aside from dumping the forward zone in bind or doing a ping -c .1 subnet.1-254? I want to find something I can call from a script to return the list to either a single variable or an array.
I'm open to anything, but would prefer a BASH or c solution.
I use my Nexus One. Use to use my iPhone. Lots of apps for that.
When no tools at hand: ping -c 2 -b <broadcast IP> (something like 192.168.1.255 - You need -b option) -c 2 sends just two pings. No need to get crazy.
then immediatly do
/sbin/arp -n
And you will have a list of hosts by IP.
Damn, I should have waited for your answer :p I did it the hard way with arpd, but it worked :p #!/bin/bash oifs=$IFS IFS=$'\n' declare -a arptable arptable=( $(sudo arpd -b /var/lib/arpwatch/arpd.db -l) ) printf "\n%-25s %-20s %s\n" "Hostname" "IP" "Mac" numrec=${#arptable[@]} for ((i=0;i<$numrec;i++)); do tmp=${arptable[$i]} mac=${tmp##* } ip=${tmp:1} # trim first char ip="${ip#"${ip%%[![:space:]]*}"}" # remove leading whitespace characters ip=${ip%% *} # remove mac and trailing whitespace characters hn=$(nslookup $ip) hn=${hn##*= } hn=${hn%%.*} [[ $hn =~ Server: ]] && hn="gateway (Linksys)" [[ $i -gt 0 ]] && printf "%-25s %-20s %s\n" $hn $ip $mac done -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org