Checking on internet - solved

Checking on internet - solved

Postby driessen » Fri Oct 27, 2017 7: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.
Last edited by driessen on Tue Oct 31, 2017 12:18 pm, edited 3 times in total.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking on internet

Postby Enrico Maria Giordano » Fri Oct 27, 2017 8:15 pm

This is a sample:

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Checking on internet - solved

Postby driessen » Fri Oct 27, 2017 9: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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking on internet - solved

Postby Enrico Maria Giordano » Sat Oct 28, 2017 8:04 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Checking on internet - not solved yet

Postby driessen » Mon Oct 30, 2017 3: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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking on internet - not solved yet

Postby Enrico Maria Giordano » Mon Oct 30, 2017 3:36 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Checking on internet - not solved yet

Postby driessen » Mon Oct 30, 2017 3:47 pm

Enrico,

Thanks. I will do that.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking on internet - not solved yet

Postby karinha » Mon Oct 30, 2017 7:09 pm

Maybe:

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 23 guests