WAN IP

WAN IP

Postby Bayron » Tue Dec 13, 2011 5:06 am

A while ago, somebody was asking to get this IP...
I'll be nice to have it in FiveWin:

Code: Select all  Expand view
// IP WAN address PHP script access with C/C++ on Windows OS
// http://show-ip.net/mini/
//
// getip.c
// cl getip.c  wininet.lib  user32.lib

#include <windows.h>
#include <wininet.h>
#include <stdio.h>

char output[16];
char getipurl[30] = "http://getip.110mb.com/mini/";
// char getipurl[45] = "http://getip.110mb.com/mini/index.php?v=ahp";
// adjust ReadSize value



int GetIP(char *url)
{
    HINTERNET hInternet;
    HINTERNET hFile;
    DWORD ReadSize;
    BOOL  bResult;
        
    hInternet = InternetOpen(
        "Some USER-AGENT",
        INTERNET_OPEN_TYPE_PRECONFIG,
        NULL,
        NULL,
        0);


    hFile = InternetOpenUrl(
        hInternet,
                url,
        NULL,
        0,
        INTERNET_FLAG_RELOAD,
        0);

   
        ReadSize = 15;
        bResult = InternetReadFile(
            hFile,
            output,
            15,
            &ReadSize);

       
    output[ReadSize] = '\0';
   
        printf("\n IP: %s\n", output);
     
    InternetCloseHandle(hFile);
    InternetCloseHandle(hInternet);
        return 0;
}


int main()
{
 GetIP(getipurl);
 return 0;
}
 


a zip file with .EXE and .C can be found here:

http://show-ip.net/download/getip/getip.zip
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: WAN IP

Postby driessen » Tue Dec 13, 2011 10:24 am

Hello,

This is the code I use to get the internal and the external IP-address :
Code: Select all  Expand view
#INCLUDE "FIVEWIN.CH"
#DEFINE DEFAULT(xVar,xVal) xVar=IF(xVar=NIL,xVal,xVar)
******************************************************************************

FUNCTION IP_ADRES(nSec)

   LOCAL oHttp

   LOCAL cVar1     := ""
   LOCAL cVar2     := ""
   LOCAL cSec      := 0

   LOCAL cIPADRES1 := "www.dnsstuff.com/docs/ipall"
   LOCAL cIPADRES2 := "Your IP Address: <strong>"
   LOCAL cIPADRES3 := "</strong>"

   DEFAULT(nSec,"0")

   cSec := VAL(nSec)

   WsaStartUp()
   cVar1 := GetHostByName(GetHostName())
   WsaCleanUp()

   oHttp := CreateObject("winhttp.winhttprequest.5.1")
   oHttp:Open("GET","http://"+ALLTRIM(cIPADRES1),.f.)
   oHttp:Send()
   cVar2 := oHttp:ResponseText()
   cVar2 := StrExtract(cVar2,ALLTRIM(cIPADRES2),ALLTRIM(cIPADRES3))

   IF cSec = 0
      MsgAlert(IF(!EMPTY(cVar1),"Your current internal IP-address is : "+ALLTRIM(cVar1)+IF(!EMPTY(cVAR2),CHR(13)+CHR(13),""),"") + IF(!EMPTY(cVar2),"Your current external IP-address is : "+ALLTRIM(cVar2),""),"Attention")
   ELSE
      MsgWait(IF(!EMPTY(cVar1),"Your current internal IP-address is : "+ALLTRIM(cVar1)+IF(!EMPTY(cVAR2),"       -       ",""),"") + IF(!EMPTY(cVar2),"Your current external IP-address is : "+ALLTRIM(cVar2),""),"Attention",cSec)
   ENDIF

   QUIT

RETURN(.T.)

******************************************************************************

STATIC FUNCTION StrExtract(cText,cAfter,cBefore)

   LOCAL cRet := SUBSTR(cText,AT(cAfter,cText) + LEN(cAfter))
   LOCAL n

   IF (n := AT(cBefore,cRet)) > 0
      cRet := LEFT(cRet,n - 1)
   ENDIF

RETURN(cRet)

******************************************************************************

FUNCTION OleInvoke(hObj,cMethod,uParam)

#IFNDEF __XHARBOUR__
   RETURN __ObjSendMsg(TOleAuto():New(hObj),cMethod,uParam)
#ELSE
   LOCAL aParams := hb_aParams()
   aParams[1] := TOleAuto():New(hObj)
   RETURN hb_execFromArray(@__ObjSendMsg(),aParams)
#ENDIF

******************************************************************************

FUNCTION OleSetProperty(hObj,cPropName,uValue)

RETURN __ObjSendMsg(TOleAuto():New(hObj),"_" + cPropName,uValue)

******************************************************************************

FUNCTION OleGetProperty(hObj,cPropName)

RETURN __ObjSendMsg(TOleAuto():New(hObj),cPropName)

****************************************************************************** 
It works very well.
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: WAN IP

Postby pablovidal » Tue Dec 13, 2011 11:41 am

Code: Select all  Expand view
Function PublicIP()
Local cBuffer, cRequest, cResponse, nBytes, pSocket

 INetInit()
  pSocket := INetConnect( "checkip.dyndns.org", 80 )

  IF INetErrorCode( pSocket ) <> 0
   ? "Socket error:", INetErrorDesc( pSocket )
   INetCleanUp()
   QUIT
  ENDIF

  nBytes   := INetSend( pSocket, "GET / HTTP/1.1" + CRLF + "Host: checkip.dyndns.org" + CRLF + "User-Agent: HTTP-Test-Program" + CRLF + CRLF )
  cBuffer  := Space(512)
  cResponse:= ""

  WHILE ( nBytes > 0 )
   nBytes    := INetRecv( pSocket, @cBuffer )
   cResponse += Left( cBuffer, nBytes )
   cBuffer   := Space(512)
  ENDDO

  INetClose( pSocket )
 INetCleanUp()

Return( allTrim( substr( substr( cResponse, rat( "<body>", cResponse ) + 26 ), 1, At( "<", substr( cResponse, rat( "<body>", cResponse ) + 26 ) ) - 1 ) ) )
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: WAN IP

Postby Marc Vanzegbroeck » Tue Dec 13, 2011 11:48 am

Bayron,

I get an alert of McAfee if I want to extract getip.exe of the zip file.
It says 'Trojan Generic.dx!vsu!' found :(

Regards,
Marc
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: WAN IP

Postby Marc Vanzegbroeck » Tue Dec 13, 2011 12:00 pm

Michel,

I get this error:

    Application
    ===========
    Path and name: c:\FWH\Projects\_Test\GetIP\leesip.exe (32 bits)
    Size: 1,300,992 bytes
    Time from start: 0 hours 0 mins 0 secs
    Error occurred at: 12/13/11, 12:57:50
    Error description: Error winhttp.winhttprequest.5.1/16389 E_FAIL: SEND
    Args:

    Stack Calls
    ===========
    Called from: win32ole.prg => TOLEAUTO:SEND(0)
    Called from: leesip.prg => IP_ADRES(27)

Probably because I still use FW710 :(

Regards,
Marc
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: WAN IP

Postby driessen » Tue Dec 13, 2011 2:57 pm

Marc,

The fact that you still use FW 7.10 is indeed the reason why this error occurs.

But I'm prepared to send you my executable. Just send me your e-mail please.
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: WAN IP

Postby Bayron » Tue Dec 13, 2011 4:50 pm

I tested Michel's and Pablo's code, and they both work great...

Thank you for sharing...

Now it comes to me that I don't need NO-IP any more...

How???

Run this function in my computer with a timer (The same that NO-IP does) and save the Public IP in a MySQL database,
Using PHP, obtain that IP, and redirect the web page as I need...

I won't get the domain name as NO_IP, but I don't really need it anyway...
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: WAN IP

Postby Marc Vanzegbroeck » Tue Dec 13, 2011 5:34 pm

Michel,

It's nice of you that you want to send the exe to me, but then I still can't use/link it in my programs.
Thanks anyway,

Regards,
Marc
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 75 guests