Mailinglist Archive: opensuse (882 mails)

< Previous Next >
Re: [opensuse] How to find list of hosts on local subnet? [Part Solved]
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Thu, 02 Dec 2010 18:43:46 -0600
  • Message-id: <4CF83D42.6090104@xxxxxxxxxxxxxxxxxx>
On 12/02/2010 06:15 PM, John Andersen wrote:
On 12/2/2010 3:37 PM, David C. Rankin wrote:

What would I use to get a list of hosts on the local subnet aside from
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 - You need -b
-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.


I should have waited for your answer :p I did it the hard way with
arpd, but
it worked :p



declare -a arptable
arptable=( $(sudo arpd -b /var/lib/arpwatch/arpd.db -l) )

printf "\n%-25s %-20s %s\n" "Hostname" "IP" "Mac"


for ((i=0;i<$numrec;i++)); do
mac=${tmp##* }
ip=${tmp:1} # trim first char
ip="${ip#"${ip%%[![:space:]]*}"}" # remove leading whitespace characters
ip=${ip%% *} # remove mac and trailing whitespace
hn=$(nslookup $ip)
hn=${hn##*= }
[[ $hn =~ Server: ]] && hn="gateway (Linksys)"
[[ $i -gt 0 ]] && printf "%-25s %-20s %s\n" $hn $ip $mac

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
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups