Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:



IcmpSendEcho do www.google.com

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: IcmpSendEcho do www.google.com

Autor: 0xenon

14:48:45 10.05.2010

co se tyce toho dema, tak to uprav takhle:

// Set some reasonable default values
ipInfo.Ttl = 255;
ipInfo.Tos = 0;
ipInfo.IPFlags = 0;
ipInfo.OptSize = 0;
ipInfo.Options = NULL;
icmpEcho.Status = 0;
BYTE data[32];
icmpEcho.pData = data;
icmpEcho.DataSize = sizeof data;

// Reqest an ICMP echo
pIcmpSendEcho(
hndlFile, // Handle from IcmpCreateFile()
*dwAddress, // Destination IP address
0, // Pointer to buffer to send
0, // Size of buffer in bytes
&ipInfo, // Request options
&icmpEcho, // Reply buffer
sizeof icmpEcho + sizeof data,
1000); // Time to wait in milliseconds
// Print the results
iaDest.s_addr = icmpEcho.Source;

// Close the echo request file handle
pIcmpCloseHandle(hndlFile);

return !icmpEcho.Status;

Citovat příspěvek

 

Re: IcmpSendEcho do www.google.com

Autor: veronisoft77

16:57:32 30.04.2010

Tu je este lepsi priklad tento kod ping na www.google.com vyhadzuje chybu
IcmpSendEcho failed with error code: 11050 neviete preco?

#include "stdafx.h"
#include "Ping3.h"
#include "windows.h"
#include "conio.h"
#include "Iphlpapi.h"
#include "Icmpapi.h"

#pragma comment(lib, "IPHLPAPI.lib")

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;


void ping(char *destination);

int _tmain(int argc, _TCHAR* argv[])
{
ping("www.google.com");

cout << "\nPress any key...";
getch();
return 0;
}

void ping(char *destination)
{
WSADATA wsaData;
WSAStartup(0x0202, &wsaData);

hostent* remoteHost;
remoteHost = gethostbyname(destination);
if (WSAGetLastError() != 0)
{
cout << "Ping request could not find host "
<< destination
<< ". Please check the name and try again.\n" << endl;
WSACleanup();
return;
}

HANDLE hIcmpFile = IcmpCreateFile();
if (hIcmpFile==INVALID_HANDLE_VALUE)
{
cout << "IcmpCreateFile failed with error code: "
<< GetLastError() << endl;
WSACleanup();
return;
}

IPAddr* ipaddr = reinterpret_cast< IPAddr* >
(remoteHost->h_addr_list[0]);

cout << "Pinging " << destination << " ["
<< inet_ntoa(*reinterpret_cast< in_addr* >(ipaddr))
<< "]\n" << endl;

LPVOID ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY));

for (int i=0; i<3; i++)
{
if (IcmpSendEcho(hIcmpFile, *ipaddr,
0,0,NULL, ReplyBuffer,sizeof(ICMP_ECHO_REPLY),1000)==0)
{
cout << "IcmpSendEcho failed with error code: "
<< GetLastError() << endl;
}
else
{
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
in_addr ipreplied;
ipreplied.S_un.S_addr=pEchoReply->Address;

cout << "Reply from " << inet_ntoa(ipreplied)
<< ": bytes=" << pEchoReply->DataSize
<< " time=" << pEchoReply->RoundTripTime << "ms" << endl;
}
Sleep(500);
}

cout << endl;
free(ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
WSACleanup();
}

Citovat příspěvek

 

Re: IcmpSendEcho do www.google.com

Autor: veronisoft77

9:52:39 30.04.2010

Tu je exe aplikacia na ktorom sa da vyskusat ping do www.google.com
http://veronisoft.hostei.com/cping_exe.zip

ktoru som niekde nasiel na internete

Citovat příspěvek

 

Re: IcmpSendEcho do www.google.com

Autor: veronisoft77

9:36:31 30.04.2010

Tu je aj cely projekt na ktorom sa da vyskusat ping do www.google.com
http://veronisoft.hostei.com/cping_demo.zip

Citovat příspěvek

 

IcmpSendEcho do www.google.com

Autor: veronisoft77

16:54:01 08.04.2010

Neviete niekto preco Ping cez IcmpSendEcho do www.google.com vyhadzuje ze host je off-Line ked normaly ping funguje ako On-Line? Na ine servery funguje ako normalny ping.

void CPingDlg::OnBnClickedButton1()
{
char strHost[]= "www.google.com";
HANDLE hIcmpFile;
IPAddr ipaddr = INADDR_NONE;
DWORD dwRetVal = 0;
char SendData[] = "IP Net Verify";
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;

ipaddr = inet_addr(strHost);
if (ipaddr == INADDR_NONE)
{
hostent* hp = gethostbyname(strHost);
if( hp )
{
// int xxx = sizeof(hp->h_addr );
memcpy(&ipaddr,hp->h_addr,hp->h_length);
}
else
return;
}

hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE) {
// printf("\tUnable to open handle.\n");
// printf("IcmpCreatefile returned error: %ld\n", GetLastError() );
return;
}

//ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
ReplyBuffer =(VOID*) malloc(ReplySize);
if (ReplyBuffer == NULL) {
// printf("\tUnable to allocate memory\n");
return;
}

IP_OPTION_INFORMATION ipOptions;
memset(&ipOptions, 0, sizeof(IP_OPTION_INFORMATION));

ipOptions.Ttl = 255;
ipOptions.Flags = NULL;

dwRetVal = IcmpSendEcho( hIcmpFile, ipaddr,(LPVOID) SendData, sizeof(SendData), &ipOptions, ReplyBuffer, ReplySize, 3000 );

// Sleep( netsetting.TimeOut );
/*DWORD gle = GetLastError();
const DWORD dwMessSize = 1024;
TCHAR szBuff[dwMessSize];
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, gle , NULL,
szBuff, dwMessSize, NULL );
AfxMessageBox( szBuff ); */
IcmpCloseHandle( hIcmpFile );

if (dwRetVal != 0)
{
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
// AfxMessageBox( CString( (CHAR*)pEchoReply->Data ) );
struct in_addr ReplyAddr;
ReplyAddr.S_un.S_addr = pEchoReply->Address;
if( pEchoReply->Status != IP_SUCCESS )
{
free( ReplyBuffer );
AfxMessageBox( "Offline" );
return;
}
if( pEchoReply->Address != ipaddr )
{
free( ReplyBuffer );
AfxMessageBox( "Offline" );
return;
}
if( strcmp( SendData, (CHAR*)pEchoReply->Data ) != 0 )
{
free( ReplyBuffer );
AfxMessageBox( "Offline" );
return;
}
//AfxMessageBox( CString( inet_ntoa( ReplyAddr ) ) );
if (dwRetVal > 1)
{
// printf( "\tReceived %ld icmp message responses\n", dwRetVal);
// printf( "\tInformation from the first response:\n");
}
else
{
// printf( "\tReceived %ld icmp message response\n", dwRetVal);
// printf( "\tInformation from this response:\n");
}
// printf( "\t Received from %s\n", inet_ntoa( ReplyAddr ) );
// printf( "\t Status = %ld\n", pEchoReply->Status );
// printf( "\t Roundtrip time = %ld milliseconds\n", pEchoReply->RoundTripTime);
}
else
{

free( ReplyBuffer );
AfxMessageBox( "OffLine" );
return;
}

free( ReplyBuffer );
AfxMessageBox( "OnLine" );
return;
}

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: