 |
| 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
|
|
|

February 23rd, 2005, 02:23 AM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
|
|
ping in c++
hi.
i want ping a computer in c++ language .
please tell me one command (or source code)for this work.
tanx.
|

April 1st, 2005, 11:35 AM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
#include<windows.h>
int main()
{
system("ping xxx.xxx.xxx.xxx")
return 0;
}
play with that ;)
|

April 2nd, 2005, 02:04 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

April 16th, 2005, 11:48 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 18th, 2007, 05:32 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

June 18th, 2007, 08:30 PM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 26th, 2007, 12:15 PM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

November 19th, 2007, 03:38 PM
|
|
Registered User
|
|
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 9th, 2008, 01:34 PM
|
|
Registered User
|
|
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I compiled it in Dev C++ with no errors, it works perfect. Thx :)
|
|
 |