LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-08-2008, 03:21 AM   #1
hypercondor
LQ Newbie
 
Registered: May 2008
Distribution: Slackware
Posts: 8

Rep: Reputation: 0
Simple...ish ping script.


Ok i am making a script that will ping all active computers on the network and then output the the IP and hostnames to the screen.
So far i have
Code:
#!/bin/sh
echo
echo Machines responding on Network Address:  192.168.1.0
ping -b -c4 192.168.1.0 | grep "icmp_seq=1" | cut -f4 -d' ' | cut -f1 -d:
echo
My problem is that i cant think of a way to get rid of the
Code:
WARNING: pinging broadcast address
message, any help would be grateful
 
Old 05-08-2008, 04:39 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
#!/bin/sh
echo
echo Machines responding on Network Address:  192.168.1.0
ping -b -c4 192.168.1.0 2>/dev/null| grep "icmp_seq=1" | cut -f4 -d' ' | cut -f1 -d:
echo
Do you actually get responses? My switch would stop
that kind of non-sense ;}


Cheers,
Tink

Last edited by Tinkster; 05-08-2008 at 04:41 AM.
 
Old 05-08-2008, 02:23 PM   #3
thronh
LQ Newbie
 
Registered: Jan 2006
Posts: 9

Rep: Reputation: 0
You could always use nmap for your ping list. It takes a bit longer, but it gets rid of the warning.

nmap -sP 192.168.1.0-255 |sed '1,2 d'
 
Old 05-08-2008, 04:56 PM   #4
viron
Member
 
Registered: Dec 2005
Location: McKinney, Texas
Distribution: Slackware
Posts: 40

Rep: Reputation: 15
Quote:
Originally Posted by hypercondor View Post
Ok i am making a script that will ping all active computers on the network and then output the the IP and hostnames to the screen.
So far i have
Code:
#!/bin/sh
echo
echo Machines responding on Network Address:  192.168.1.0
ping -b -c4 192.168.1.0 | grep "icmp_seq=1" | cut -f4 -d' ' | cut -f1 -d:
echo
My problem is that i cant think of a way to get rid of the
Code:
WARNING: pinging broadcast address
message, any help would be grateful
Try the following:

ping -b -c4 192.168.1.0 | grep "icmp_seq=1" | cut -f4 -d' ' | cut -f1 -d: | sed -e 's/WARNING: pinging broadcast address//g'
 
Old 05-08-2008, 05:20 PM   #5
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
^ add | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4


to sort the IP by order.
 
Old 05-08-2008, 11:08 PM   #6
hypercondor
LQ Newbie
 
Registered: May 2008
Distribution: Slackware
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks for the replys guys, I worked it out on my own in the end. i ended up scrapping the ping and using nmap as it made it alot easier to display the hostname.
Quote:
#!/bin/sh
echo
echo Machines responding on Network Address: 192.168.200.0
nmap -sP 192.168.200.* | grep ".esf" | cut -f2,3 -d' '
echo
Basically it was a code that i would use when i ssh to my linux lab at uni so i could see which machines were up and running.

oh and Tink
Quote:
Originally Posted by Tinkster View Post
Code:
#!/bin/sh
echo
echo Machines responding on Network Address:  192.168.1.0
ping -b -c4 192.168.1.0 2>/dev/null| grep "icmp_seq=1" | cut -f4 -d' ' | cut -f1 -d:
echo
Do you actually get responses? My switch would stop
that kind of non-sense ;}


Cheers,
Tink
No i dont get responses at my house as my switch also blocks out broadcast pings, but the uni lab doesnt.

Last edited by hypercondor; 05-08-2008 at 11:10 PM.
 
  


Reply



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
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Simple question about command syntax ping/log ping results ohalnet Linux - Networking 1 07-25-2006 04:46 AM
Simple Ping problem bkesting Linux - Networking 11 11-30-2004 02:53 PM
Ping - Surely this should be simple???? chaste Linux - Networking 8 08-06-2002 08:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:37 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
Open Source Consulting | Domain Registration