LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-04-2010, 02:33 PM   #1
medeiom
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Rep: Reputation: 0
Writing a command (for loop) that would ping a Class C subnet


Hello all,

Does anyone know how to write a command (for loop) that would ping a Class C subnet to make it so that it only replies once and does not show the statistics???

Your help is much appreciated!
 
Old 11-04-2010, 10:04 PM   #2
mf93
Member
 
Registered: Jun 2009
Distribution: Debian Squeeze, centOS
Posts: 229

Rep: Reputation: 36
you could do it in a bash script-

Code:
#!/bin/bash
echo "Class C address range?"
read address
for final in `seq 1 254`;do
ping $address.$final -c 1 | cut -f1 -d":"
done
 
Old 11-05-2010, 09:31 AM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Ubuntu, Amazon Linux
Posts: 1,830
Blog Entries: 21

Rep: Reputation: 119Reputation: 119
In just a command:

Code:
seq 1 254|while read n;do ping -c1 192.168.1.$n|cut -d: -f1|grep from;done
Use your own network numbers, of course.
 
Old 03-17-2012, 09:49 AM   #4
SPF
Member
 
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 37

Rep: Reputation: 15
I think it's a bit slow.
I'm using the following method:
Code:
#!/bin/bash
if [ ! -z "$1" ]; then
  ping -w 1 -c 1 -t 1 $1 > /dev/null
  if [ $? -eq 0 ]; then
    echo "$1 UP"
  fi
else
  IP=`ip addr show eth0 | grep "inet " | tr "/" " " | awk '{print $2}'`
  CLASSA=`echo $IP | sed 's/\.[^.]*$//'`
  for ip in $(seq 1 254)
  do
    bash $0 $CLASSA.$ip &
  done
fi
It will give you the result within 3 seconds:
Quote:
192.168.1.1 UP
192.168.1.2 UP
192.168.1.3 UP
192.168.1.70 UP
192.168.1.122 UP
192.168.1.127 UP
192.168.1.202 UP
192.168.1.241 UP
And you could add it to your .bashrc:
Code:
alias ping_all='bash /home/spf/scripts/ping_all.sh'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setup with 2 ethernet interfaces and 2 IP addresses in the same subnet of a class C ursusca Linux - Networking 3 12-25-2008 05:21 PM
ping an ip from an interface with an ip of another subnet kpachopoulos Linux - Networking 1 09-01-2006 05:05 AM
Can ping subnet one way, but not the other ghight Linux - Networking 4 10-14-2005 10:00 AM
Can't ping any PC outside subnet mrpc_cambodia Red Hat 2 10-07-2004 09:48 PM
class c subnet ip's acid_kewpie General 1 03-12-2002 07:39 AM


All times are GMT -5. The time now is 10:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration