Saludos amigos,
En el área de almacén tengo el problema que apagan el router y cuando inician su módulo les lanza un error porque evidentemente no hay conexión con el servidor. Quería consultarles si existe en Harbour una función similar a "Ping" del DOS, para verificar la disponibilidad de la red. Sé que puedo hacer un .batch y ejecutarlo con EXECUTE FILE pero quise consultarles si conocen alguna función en Harbour que haga lo mismo.
Agradeciendo su ayuda, reciban mis cordiales saludos.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Greetings, friends
In the warehouse area I have the problem that they turn off the router and when they start their module it throws an error because obviously there is no connection to the server. I wanted to ask if there is a function in Harbor similar to "Ping" of DOS, to verify the availability of the network. I know I can do a .batch and execute it with EXECUTE FILE but I wanted to ask if you know any function in Harbour that does the same.
Thank you for your help, receive my cordial greeting.
Función PING en Harbour / PING function in Harbour
Moderator: Rathinagiri
- edufloriv
- Posts: 238
- Joined: Thu Nov 08, 2012 3:42 am
- DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
- Location: PERU
Función PING en Harbour / PING function in Harbour
Eduardo Flores Rivas
LIMA - PERU
Re: Función PING en Harbour / PING function in Harbour
Maybe it will be helpful: http://www.hmgforum.com/viewtopic.php?p=51824#p51824
Re: Función PING en Harbour / PING function in Harbour
Quizá algo de aquí pueda servir...
------------------------------------------
Maybe something here can serve ...
http://www.hmgforum.com/viewtopic.php?f ... tem#p32282
------------------------------------------
Maybe something here can serve ...
http://www.hmgforum.com/viewtopic.php?f ... tem#p32282
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
Re: Función PING en Harbour / PING function in Harbour
Ping command in Harbour is here
Attached working example, change xurl := "www.google.com" to xurl := 192.168.1.1 etc.
Attached working example, change xurl := "www.google.com" to xurl := 192.168.1.1 etc.
Code: Select all
/*
Check Internet connectivity through PING command and it is reliable
From bpd2000
Expert help from KDJ
*/
#include "hmg.ch"
FUNCTION MAIN()
Local xerrdescription , xurl := "www.google.com"
xerrdescription := HB_PING(xurl)
Do Case
Case xerrdescription = 0
MSGINFO("Ping to " + xurl + " Succesful", "Internet Connection Available")
Case xerrdescription = 11001
MSGINFO("The reply buffer was too small.")
Case xerrdescription = 11002
MSGINFO("The destination network was unreachable.")
Case xerrdescription = 11003
MSGINFO("The destination host was unreachable.")
Case xerrdescription = 11004
MSGINFO("The destination protocol was unreachable.")
Case xerrdescription = 11005
MSGINFO("The destination port was unreachable.")
Case xerrdescription = 11006
MSGINFO("Insufficient IP resources were available.")
Case xerrdescription = 11007
MSGINFO("A bad IP option was specified.")
Case xerrdescription = 11008
MSGINFO("A hardware error occurred.")
Case xerrdescription = 11009
MSGINFO("The packet was too big.")
Case xerrdescription = 11010
MSGINFO("The request timed out." + hb_osnewline() +"Internet Connection Not Available")
Case xerrdescription = 11011
MSGINFO("A bad request.")
Case xerrdescription = 11012
MSGINFO("A bad route.")
Case xerrdescription = 11013
MSGINFO("The time to live (TTL) expired in transit.")
Case xerrdescription = 11014
MSGINFO("The time to live expired during fragment reassembly.")
Case xerrdescription = 11015
MSGINFO("A parameter problem.")
Case xerrdescription = 11016
MSGINFO("Datagrams are arriving too fast to be processed" + hb_osnewline() + ;
" and datagrams may have been discarded.")
Case xerrdescription = 11017
MSGINFO("An IP option was too big.")
Case xerrdescription = 11018
MSGINFO("A bad destination.")
Case xerrdescription = 11050
MSGINFO("A general failure" + hb_osnewline() + ;
"This error can be returned for some malformed ICMP packets.")
Otherwise
msginfo("Internet Connection Not Available")
ENDCASE
RETURN NIL
//https://groups.google.com/forum/#!topic/harbour-users/Jag2rPxWK_U
#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 = INADDR_NONE; // corrected by KDJ
DWORD dwRetVal;
char SendData[32] = "Data Buffer";
LPVOID ReplyBuffer;
DWORD ReplySize;
if( isalpha( cp[0] ) ) //host address is a name
{
WSADATA wsaData;
int iResult;
iResult = WSAStartup( MAKEWORD(2, 2), &wsaData );
if( iResult == 0 )
{
struct hostent *remoteHost = gethostbyname( cp );
if( remoteHost != NULL )
ipaddr = *(unsigned long *) remoteHost->h_addr_list[0];
WSACleanup();
}
}
else
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)
{
IcmpCloseHandle(hIcmpFile);
return 3;
}
dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
NULL, ReplyBuffer, ReplySize, 1000);
free(ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
if (dwRetVal == 0)
return GetLastError();
return 0;
}
HB_FUNC( HB_PING )
{
hb_retni( hb_Ping( hb_parc( 1 ) ) );
}
#pragma ENDDUMP
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG