FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Internal and external ip-address
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Internal and external ip-address
Posted: Tue Nov 10, 2009 09:22 AM
Hello,

Someone provided me with this code to get the internal and external ip-address.
Code (fw): Select all Collapse
FUNCTION IP_ADDRESS

   LOCAL oHttp
   LOCAL cVar1 := ""
   LOCAL cVar2 := ""

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

   TRY
      oHttp := CreateObject("winhttp.winhttprequest.5.1")
      oHttp:Open("GET","http://www.ip-adress.com/",.f.)
      oHttp:Send()
      cVar2 := oHttp:ResponseText()
      cVar2 := StrExtract(cVar2,"My IP address: ","</h2>")
   CATCH
   END

RETURN(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),""))

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

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)


But since a few days ago, this code isn't working anymore.

Does anyone has any idea why ?

Thanks a lot in advance 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: 172
Joined: Fri Oct 07, 2005 01:29 PM
Re: Internal and external ip-address
Posted: Tue Nov 10, 2009 09:47 AM
The text on http://www.my-ip-address.com has changed.

Change

Code (fw): Select all Collapse
   cVar2 := StrExtract(cVar2,"My IP address: ","</h2>")


to

Code (fw): Select all Collapse
   cVar2 := StrExtract(cVar2,"My IP address is: ","</h2>")
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Internal and external ip-address
Posted: Tue Nov 10, 2009 02:20 PM

Alex,

Thanks a lot for trying to help me.

I noticed that I was using www.ip-address.com while you mentioned www.my-ip-address.com.

I tried both URL's but it still isn't working. I got always got a whole page of something that looks like html- of xml-code.

Any idea ?

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: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Internal and external ip-address
Posted: Tue Nov 10, 2009 02:48 PM
Neither address works. You can use http://www.dnsstuff.com/docs/ipall
Then you can use the extraction string for IP Address as follows:
cIPAddress := StrExtract(cIPAddress,"Your IP Address: <strong>","</strong>")
and for physical location:
cLocation := StrExtract(cLocation,"Located near: <strong>","</strong>")
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Internal and external ip-address - solved
Posted: Tue Nov 10, 2009 04:40 PM

Thank you very much for your advice.

My function is working fine now.

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

Continue the discussion