Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 27th, 2005, 11:18 AM
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to cabanaworld Send a message via Yahoo to cabanaworld
Default Multiple Host Ping Programm Code HELP!

Sorry for being a newbie . . . I am looking for source code for a program that does the following:

1. Pings SPECIFIC Multiples Hosts on a Network (IP or Name via DNS).
2. Then have the results of the pings (wether the machine is alive or not on the network) to a file.

I have a list of about 300 machines that are supposedly in our network and dont want to have to use Windows CMD prompt and enter each individually to find out if indeed they are. Any suggestions would be appreciated.

PS This does not have to be GUI. I just need o compile and execute. I will copy and paste the HOST names into the Source Code. Please help!

I would also be open to run on Linux if anyone can come up with code for that.
Reply With Quote
  #2 (permalink)  
Old April 28th, 2005, 09:41 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

OK, this is a perl script that'll do it for you on a linux box.

You can use this in 2 ways (both examples output their data to a file called log.txt, only successful pings are output):

1. With a data file, 1 IP/Hostname per line.
  $ ./multiping.pl <filename> > log.txt

2. From the commandline, give it 1 IP/Hostname per line and end the list with ctrl-d, exit, or quit.
  $ ./multiping.pl > log.txt
  127.0.0.1
  1.0.0.127
  google.com
  quit

Example output (from eg.2):
  $ cat log.txt
  127.0.0.1 : 1 packets transmitted, 1 received, 0% packet loss, time 0ms
  google.com : 1 packets transmitted, 1 received, 0% packet loss, time 0ms

Code:
#!/usr/bin/perl
#
# multiping.pl: ping multiple hosts from a linux box
#
# Copyright (C)2005 Charlie Harvey
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# use_less_, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# Also available on line: http://www.gnu.org/copyleft/gpl.html

use strict;
my @ping_array=();

# read input from stdin.
while(<>) {
        last if (/exit|quit/i);
        chomp;
        # actually do the ping
        my $ping_result = `ping -q -c1 $_ | tail -n2 |head -n1`;
        chomp $ping_result;
        push @ping_array, "$_ :\t$ping_result";
}

foreach (@ping_array) {
        # only print out this result if there was 0% packet loss.
        next unless ($_=~/ 0% packet loss/i);
        print "$_\n";
}

######END

HTH
Charlie



--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
Reply With Quote
  #3 (permalink)  
Old April 28th, 2005, 09:55 AM
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to cabanaworld Send a message via Yahoo to cabanaworld
Default

I will try this out today. THANKS YOU VERY MUCH for your help ciderpunx. ALL help is appreciated!
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
ping in c++ assareh C++ Programming 10 August 5th, 2009 10:15 AM
ping multiple address khodijah C++ Programming 1 October 10th, 2007 11:14 PM
Troubles with Programm AlisaSmi Excel VBA 0 March 7th, 2007 07:50 AM
multiple sites ping program acquiesce11 Python 2 November 13th, 2006 11:08 AM
Ping another computer Phreaky .NET Web Services 0 January 18th, 2006 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.