Wrox Programmer Forums
|
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 February 23rd, 2005, 02:23 AM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default ping in c++

hi.
i want ping a computer in c++ language .
please tell me one command (or source code)for this work.
tanx.
Reply With Quote
  #2 (permalink)  
Old February 25th, 2005, 03:21 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bmagness
Default

There isn't one function you can call. I suggest that you use ICMP to ping. Go to www.msdn.com and search on ICMP. This link might work:

http://support.microsoft.com/default...b;en-us;170591
Reply With Quote
  #3 (permalink)  
Old April 1st, 2005, 11:35 AM
syn syn is offline
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

#include<windows.h>
int main()
{
  system("ping xxx.xxx.xxx.xxx")
  return 0;
}

play with that ;)

Reply With Quote
  #4 (permalink)  
Old April 2nd, 2005, 02:04 AM
Authorized User
 
Join Date: Mar 2005
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

If you make a C++ program to execute the ping command it will just duplicate the existing internal Ping command. Why bother?

Why not go straight to the Command window in Windows and enter the ping command there?

C:>ping xxx.xxx.xxx.xxx.

C:>exit

Alan

Reply With Quote
  #5 (permalink)  
Old April 16th, 2005, 11:48 AM
Authorized User
 
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths
Default

Maybe his computer is doing more ... i.e. a portscanner that pings first? That's what I do, 'cause it's way easier to write a program that opens ports in a tight loop than to muck with ICMP from C/C++. If anybody knows an easy/portable way to muck with ICMP in C/C++ though, i'd be intrested in knowing it/seeing links. I readily accnowledge that my solution is more of a cop-out because I'm too lazy to write a lot of code.

Regards,
Meredith Shaebanyan

Reply With Quote
  #6 (permalink)  
Old June 18th, 2007, 05:32 AM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TotcoS Send a message via MSN to TotcoS Send a message via Yahoo to TotcoS
Default

Here you go..
Code:
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

static string host;
static string ping_again;

void ping()
{
     system("cls");
     cout << "Host: ";
     cin >> host;
     system (("ping " + host).c_str());
     cout << endl;
     cout << "(Y)es or (N)o\n\n";
     cout << "Ping another host: ";
     cin >> ping_again;
     if (ping_again == "Y" || ping_again == "y")
     {
     system("cls");
     ping();
     }
     else if (ping_again == "N" || ping_again == "n")
     {
     system("exit");
     }
}

int main()
{
     SetConsoleTitle("Ping in C++ by TotcoS");
     ping();

     return(0);
}
Happy Coding,
Scott Stauffer aka TotcoS of BlackHat-Forums.
Reply With Quote
  #7 (permalink)  
Old June 18th, 2007, 08:30 PM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TotcoS Send a message via MSN to TotcoS Send a message via Yahoo to TotcoS
Default

Quote:
quote:Originally posted by bmagness
 There isn't one function you can call. I suggest that you use ICMP to ping. Go to www.msdn.com and search on ICMP. This link might work:

http://support.microsoft.com/default...b;en-us;170591
Its good to learn ICMP but there is a function you can call.
Make it yourself. Or use system() calls. View my source.

I don't need a signature =D
Reply With Quote
  #8 (permalink)  
Old June 26th, 2007, 12:15 PM
Registered User
 
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is just what I needed!

But, how can I draw this output from the window for use in my program? I need to know if the computer is active or not since I am digging for files. Should I put all of the output from the pink result into a text file and then search it for target information? And if so, how? I keep hearing about piping or something along those lines, but I just want some simple way to just retrieve that output without having to break a leg over a pile of excess code.

Thanks for the help! Good questions!

- Codefishy
Reply With Quote
  #9 (permalink)  
Old November 19th, 2007, 03:38 PM
Registered User
 
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cisso
Default

Hi, i've tryed to put this code to run but it didn't compile.
my compiler didn't recognize the headers without .h , the "static strings" global declared and the "using namespace std". What compiler have you used?


Quote:
quote:Originally posted by TotcoS
 Here you go..
Code:
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

static string host;
static string ping_again;

void ping()
{
     system("cls");
     cout << "Host: ";
     cin >> host;
     system (("ping " + host).c_str());
     cout << endl;
     cout << "(Y)es or (N)o\n\n";
     cout << "Ping another host: ";
     cin >> ping_again;
     if (ping_again == "Y" || ping_again == "y")
     {
     system("cls");
     ping();
     }
     else if (ping_again == "N" || ping_again == "n")
     {
     system("exit");
     }
}

int main()
{
     SetConsoleTitle("Ping in C++ by TotcoS");
     ping();
     
     return(0);
}
Happy Coding,
Scott Stauffer aka TotcoS of BlackHat-Forums.
Reply With Quote
  #10 (permalink)  
Old February 9th, 2008, 01:34 PM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I compiled it in Dev C++ with no errors, it works perfect. Thx :)

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ping another computer Phreaky Intro Programming 2 January 23rd, 2006 01:31 PM
Ping another computer Phreaky .NET Web Services 0 January 18th, 2006 11:08 AM
Ping in web application drasko ASP.NET 1.0 and 1.1 Professional 2 November 16th, 2005 06:44 AM
Ping in VC++6 Charley Visual C++ 0 May 13th, 2004 09:28 AM
Ping another computer nvillare .NET Web Services 0 November 30th, 2003 04:05 PM





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