Adhemar, porque no funciona con
www.microsoft.com ??
Code: Select all | Expand
#include "fivewin.ch"// PRUEBA DE PING //function main
() if WSAStartup
() !=
0 MsgAlert
( "WSAStartup error" ) return nil endif /* // Funciona perfecto
if hb_Ping( GetHostByName( "www.google.com" ) ) == 0
Msginfo("Respuesta correcta del host " + AllTrim( GetHostByName( "www.google.com" ) ), "Atención" )
else
Msginfo("Host inaccesible" + AllTrim( GetHostByName( "www.google.com" ) ), "Atención" )
endif
Ping( GetHostByName( "www.google.com" ) )
*/ /* // funciona perfecto
if hb_Ping( GetHostByName( "www.lostajiboshotel.com" ) ) == 0
Msginfo("Respuesta correcta del host " + AllTrim( GetHostByName( "www.lostajiboshotel.com" ) ), "Atención" )
else
Msginfo("Host inaccesible " + AllTrim( GetHostByName( "www.lostajiboshotel.com" ) ), "Atención" )
endif
Ping( GetHostByName( "www.lostajiboshotel.com" ) )
*/ // Funciona perfecto */
if hb_Ping
( GetHostByName
( "www.hotmail.com" ) ) ==
0 Msginfo("Respuesta correcta del host " + AllTrim
( GetHostByName
( "www.hotmail.com" ) ),
"Atención" ) else Msginfo("Host inaccesible" + AllTrim
( GetHostByName
( "www.hotmail.com" ) ),
"Atención" ) endif Ping
( GetHostByName
( "www.hotmail.com" ) ) */
// Adhemar, porque no funciona con www.microsoft ?? if hb_Ping
( GetHostByName
( "www.microsoft.com" ) ) ==
0 Msginfo("Respuesta correcta del host " + AllTrim
( GetHostByName
( "www.microsoft.com" ) ),
"Atención" ) else Msginfo("Host inaccesible " + AllTrim
( GetHostByName
( "www.microsoft.com" ) ),
"Atención" ) endif Ping
( GetHostByName
( "www.microsoft.com" ) ) WSACleanUp
() return nilFunction Ping
(DestinationAddress
)Local IcmpHandle,Replicas,puerto
Local RequestData :=
"Probando ping",;
RequestSize :=
15,;
RequestOptions:=
"",;
ReplyBuffer :=SPACE
(278),;
ReplySize :=
278,;
Timeout :=
1000 && Milisegundos de espera
DEFAULT DestinationAddress :=
"127.0.0.1"DestinationAddress:=
LEFT(ALLTRIM
(DestinationAddress
)+SPACE
(15),
15)MsgGet
("Ping...",
"Ingrese una dirección IP",@DestinationAddress
)IcmpHandle:=IcmpCreateFile
()Replicas :=IcmpSendEcho
(IcmpHandle,;
inet_addr
(DestinationAddress
),;
RequestData,;
RequestSize,
0,;
ReplyBuffer,;
ReplySize,;
Timeout
)IcmpCloseHandle
(IcmpHandle
)IF Replicas >
0 Msginfo("Respuesta correcta del host "+ALLTRIM
(DestinationAddress
),
"Atención")ELSE Msginfo("Host inaccesible"+ALLTRIM
(DestinationAddress
)+
"Atención")ENDIFReturn nil//DLL32
FUNCTION WSAGetLastError
() AS _INT PASCAL
FROM "WSAGetLastError" LIB
"wsock32.dll"DLL32
FUNCTION inet_addr
(cIP AS STRING
) AS LONG PASCAL
FROM "inet_addr" LIB
"wsock32.dll"DLL32
FUNCTION IcmpCreateFile
() AS LONG PASCAL
FROM "IcmpCreateFile" LIB
"icmp.dll"DLL32
FUNCTION IcmpCloseHandle
(IcmpHandle AS LONG
) AS LONG PASCAL
FROM "IcmpCloseHandle" LIB
"icmp.dll"DLL32
FUNCTION IcmpSendEcho
(IcmpHandle AS LONG,;
DestinationAddress AS LONG,;
RequestData AS STRING,;
RequestSize AS LONG,;
RequestOptions AS LONG,;
ReplyBuffer AS LPSTR,;
ReplySize AS LONG,;
Timeout AS LONG
) AS LONG PASCAL
FROM "IcmpSendEcho" LIB
"icmp.dll"#pragma BEGINDUMP
#include <hbapi.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <icmpapi.h>
int hb_Ping
( const char * cp
){ HANDLE hIcmpFile;
unsigned long ipaddr;
DWORD dwRetVal;
char SendData
[32] =
"Data Buffer";
LPVOID ReplyBuffer;
DWORD ReplySize;
ipaddr = inet_addr
( cp
);
if (ipaddr == INADDR_NONE
) return 1;
hIcmpFile = IcmpCreateFile
();
if (hIcmpFile == INVALID_HANDLE_VALUE
) return 2;
ReplySize = sizeof
(ICMP_ECHO_REPLY
) + sizeof
(SendData
);
ReplyBuffer =
(VOID*
) malloc
(ReplySize
);
if (ReplyBuffer ==
NULL) return 3;
dwRetVal = IcmpSendEcho
(hIcmpFile, ipaddr, SendData, sizeof
(SendData
),
NULL, ReplyBuffer, ReplySize,
1000);
if (dwRetVal ==
0) return 4;
return 0;
}HB_FUNC( HB_PING
){ hb_retni
( hb_Ping
( hb_parc
( 1 ) ) );
}#pragma ENDDUMP
Gracias,