FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Checking on internet - solved
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Checking on internet - solved
Posted: Fri Oct 27, 2017 07:49 PM
Hello,

How can I check if a SMTP-server is existing?
I'd like to test it with for instance uit.telenet.be.
Thanks a lot for any help.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Checking on internet
Posted: Fri Oct 27, 2017 08:15 PM
This is a sample:

Code (fw): Select all Collapse
FUNCTION MAIN()

    ? HB_PING( "uit.telenet.be" )

    RETURN NIL


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

    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 4;
    
    return 0;

}

HB_FUNC( HB_PING )
{
   hb_retni( hb_Ping( hb_parc( 1 ) ) );
}

#pragma ENDDUMP


EMG
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Checking on internet - solved
Posted: Fri Oct 27, 2017 09:24 PM

Enrico,

Thanks a lot for your help.
It works just fine.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Checking on internet - solved
Posted: Sat Oct 28, 2017 08:04 AM

Please note: it's not my code. I don't remember where I got it from, sorry.

EMG

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Checking on internet - not solved yet
Posted: Mon Oct 30, 2017 03:32 PM

Enrico,

Do you have any idea why this code HB_PING is working fine with Harbour, but not with xHarbour Builder?
In that case, I got an error "couldn't build" without mentioning anything else.

Thanks.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Checking on internet - not solved yet
Posted: Mon Oct 30, 2017 03:36 PM

It works fine here using official xHarbour. For xHarbour Builder you have to ask for support to xHarbour.com guys.

EMG

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Checking on internet - not solved yet
Posted: Mon Oct 30, 2017 03:47 PM

Enrico,

Thanks. I will do that.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Checking on internet - not solved yet
Posted: Mon Oct 30, 2017 07:09 PM
Maybe:

Code (fw): Select all Collapse
#include "FiveWin.ch"

FUNCTION MAIN()

   LOCAL cTestPing

   // Direct of Machine(computer).
   // cTestPing := ( "http://speedtest.copel.net/" )             // Correct
   // ShellExecute(GetActiveWindow(),"open",'"'+cTestPing+'"') // correct

   // cTestPing := ( "uit.telenet.be" )  // ERROR return 0
   cTestPing := ( "http://duits.telenet.be/" )   // return 4, correct?

   ? HB_PING( cTestPing )

RETURN NIL


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

    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 4;
    
    return 0;

}

HB_FUNC( HB_PING )
{
   hb_retni( hb_Ping( hb_parc( 1 ) ) );
}

#pragma ENDDUMP
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion