Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-31-2012
Registered User
 
Join Date: Jun 2012
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Print all Host on local network

Hello guys,

I would like to develop a script which takes a host name as argument and displays a message whether the host is on the local network or not. How can I accomplish that? Is there a file or command that I can use to list all host on the local network?
Sponsored Links
    #2  
Old 07-31-2012
Registered User
 
Join Date: Nov 2010
Location: Houston, Tx
Posts: 67
Thanks: 8
Thanked 5 Times in 5 Posts
you can ping the host can compare it to you ip. If is is different than it is not local.
Sponsored Links
    #3  
Old 07-31-2012
Registered User
 
Join Date: Jun 2012
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
But this involves IP addresses, or is that also possible with a string host name i.e "UNIX01"?
    #4  
Old 07-31-2012
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Location: Aachen, Germany
Posts: 1,889
Thanks: 25
Thanked 436 Times in 421 Posts
This pertains to linux machines, may be different on others:
arp -a dumps your machine's "Address Resolution Protocol" cache, i.e. your active connections.
ping -b pings the entire local network BUT machines have to be setup to answer.

Last edited by RudiC; 07-31-2012 at 05:11 AM..
Sponsored Links
    #5  
Old 07-31-2012
Registered User
 
Join Date: Dec 2004
Location: Isle-of-Skye
Posts: 231
Thanks: 7
Thanked 26 Times in 26 Posts
Hi,

You can try this;


Code:
$ for ip in `echo '[1+pd254>aq]sa0 1-lax' | dc`; do ping -c 1 10.176.128.$ip>/dev/null; [ $? -eq 0 ] && echo "10.176.128.$ip UP" ; nslookup 10.176.128.$ip || : ; done

Where the XXX.XXX.XXX is your first three octets.

Regards

Dave

Last edited by gull04; 07-31-2012 at 05:32 AM.. Reason: Typo
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what command for copy a filesystem (local host or remote host) bora99 Linux 1 02-29-2012 07:05 AM
Help! How to find the local host after few ssh hops to remote host??? gomes1333 UNIX for Advanced & Expert Users 3 03-27-2010 10:49 PM
ssh server is attachable from local network not from another network old noob IP Networking 1 02-16-2009 07:24 PM
How to delete the files from local host to remote host krishna176 Solaris 3 03-24-2007 04:48 PM
local host tamemi UNIX for Dummies Questions & Answers 3 12-23-2003 04:44 PM



All times are GMT -4. The time now is 02:25 AM.