Re: find local computers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On March 2, 2004 08:13 am, Marty Landman wrote:
> At 08:48 PM 3/1/2004, Pete Nesbitt wrote:
> >ping cannot resolve a name, it can resolve a name to IP prior to sending
> >the packet, but it really doesn't care about names.
>
> So I can say ping -c1 penguin instead of ping -c1 192.168.0.160 if I
> already know the names of all my boxes on the lan. But what I want to do is
> have a way to find all those boxes, ip addr and host name. The host cmd
> seems fine for this, i.e. I've modified the script to run `host` for each
> ip adr found on the lan, though I haven't finished parsing it yet.
>
> >You may want to look at 'ping -b'  so send a broadcast ping, then collect
> >the results.
>
> I don't understand the man page, could you give an example please? I'd like
> to ping everything for
>
> 192.168.0. with netmask 255.255.255.0
>
> This is what I'm doing with the script now in fact, only I realize it's
> probably the hard way. At least I learned a little bash and awk though.
>
> >won't help the name resolution at all.
>
> But doing a host for each pingable ip works fine tbh so I'm happy with
> that.
>
> This script could actually be used to put together canonical hosts files,
> although it'd be lacking in hosts other than the server name for apache
> virtual hosts... hope I'm saying that right.
>
> Marty Landman   Face 2 Interface Inc.   845-679-9387
> FormATable  DB: http://face2interface.com/Products/FormATable.shtml
> Make a Website: http://face2interface.com/Home/Demo.shtml
> Free Formmailer: http://face2interface.com/Products/Formal.shtml


Hi Marty,
to ping the 192.168.1.0/24 network use:
ping -c1 -b 192.168.1.255 (just use the broadcast ip for the network)

This will not work across a router. It also appears to show all but the 
primary system as duplicates packets, which would be bad, except that 
we are pinging the whole lan.

Here is a sample, but I only have 2 systems that are pingable (paranoia):
pete@nebula temp$ ping -c1 -b 192.168.1.255
WARNING: pinging broadcast address
PING 192.168.1.0 (192.168.1.0) 56(84) bytes of data.
64 bytes from 192.168.1.50: icmp_seq=0 ttl=64 time=0.061 ms
64 bytes from 192.168.1.4: icmp_seq=0 ttl=64 time=0.192 ms (DUP!)

Do you have a local dns server?  I beleive you need a reverse DNS lookup 
for the 'host' command name to work.
If you have a local dns server for the LAN, then try this:
(mine fails as I have no reverseDNS)

I set this not to wrap, but your email client may...
1st: test at command line:
pete@nebula temp$ ping -c1 -b 192.168.1.255 2>/dev/null|grep "^64"|awk '{print $4}'|awk -F: '{print $1}'>>/tmp/ip_numbers
pete@nebula temp$ while read IP_NUM; do host $IP_NUM; done < /tmp/ip_numbers
Host 50.1.168.192.in-addr.arpa not found: 3(NXDOMAIN)
Host 4.1.168.192.in-addr.arpa not found: 3(NXDOMAIN)
pete@nebula temp$

so in a script:
LAN_BDCAST="192.168.1.255"
IP_NUMBERS=/tmp/ip_numbers
IP_HOST_FILE=/tmp/ip_2_hostnames
echo "">$IP_NUMBERS
echo "">$IP_HOST_FILE
ping -c1 -b $LAN_BDCAST 2>/dev/null|grep "^64"|awk '{print $4}'|awk -F: '{print $1}'>>$IP_NUMBERS
while read IP_NUM
 do
  host $IP_NUM >> $IP_HOST_FILE
 done <$IP_NUMBERS
 
...you get the idea.


Expanding your script to create the named files would be a great exersice, 
however, it would be of questionable value, because as I see it, you will need 
to have the DNS & reverseDNS working before you can retreive the names to 
match to IP's.

I don't know how you could get the Virtual Hosts if they are name based. 
They do need to be in DNS, so if you knew all the VH's you could ping the 
name to get the IP, but that is a different script again. The thing is you can 
only ping an IP, (pinging a name just causes a dns lookup prior to the ping) 
and the name based virtual host aspect is relavent to Apache and to DNS 
(or /etc/hosts), not the IP address.

Hope that helps.
-- 
Pete Nesbitt, rhce


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux