Internal and external ip-address

Internal and external ip-address

Postby driessen » Tue Nov 10, 2009 9:22 am

Hello,

Someone provided me with this code to get the internal and external ip-address.
Code: Select all  Expand view
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. 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: Internal and external ip-address

Postby AlexSchaft » Tue Nov 10, 2009 9:47 am

The text on http://www.my-ip-address.com has changed.

Change

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


to

Code: Select all  Expand view
  cVar2 := StrExtract(cVar2,"My IP address is: ","</h2>")
User avatar
AlexSchaft
 
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

Re: Internal and external ip-address

Postby driessen » Tue Nov 10, 2009 2: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. 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: Internal and external ip-address

Postby Gale FORd » Tue Nov 10, 2009 2: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>")
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Internal and external ip-address - solved

Postby driessen » Tue Nov 10, 2009 4: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. 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


Return to FiveWin for Harbour/xHarbour

Who is online

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