Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 23rd, 2005, 01:23 AM
Registered User
 
Join Date: Feb 2005
Location: , , .
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, 02:21 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
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, 10:35 AM
syn syn is offline
Registered User
 
Join Date: Apr 2005
Location: , , .
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, 01:04 AM
Authorized User
 
Join Date: Mar 2005
Location: Wagga Wagga, NSW, Australia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
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
Location: , , .
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
Location: Oklahoma City, Oklahoma, USA.
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
Location: Oklahoma City, Oklahoma, USA.
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
Location: , , .
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, 02:38 PM
Registered User
 
Join Date: Nov 2007
Location: São Paulo, SP, Brazil.
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, 12:34 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
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
Reply


Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ping another computer Phreaky Intro Programming 2 January 23rd, 2006 12:31 PM
Ping another computer Phreaky .NET Web Services 0 January 18th, 2006 10:08 AM
Ping in web application drasko ASP.NET 1.0 and 1.1 Professional 2 November 16th, 2005 05: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 03:05 PM



All times are GMT -4. The time now is 07:27 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.