FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Internal and external IP - solved
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM

Internal and external IP - solved

Posted: Tue Apr 19, 2016 02:12 PM
Hello,

I used to use this code to get my internal and externam IP :
Code (fw): Select all Collapse
WsaStartUp()
cVar1 := GetHostByName( GetHostName() )
WsaCleanUp()
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET","http://www.dnsstuff.com/docs/ipall",.f.)
oHttp:Send()
cVar2 := oHttp:ResponseText()
cVar2 := StrExtract(cVar2,"Your IP Address: <strong class="+CHR(34)+"ipBlock"+CHR(34)+">","</strong>")
This results into cVar1 = my internal IP, cVar2 = my external IP.

Until a short while ago, it use to work just fine. Now it doesn't work anymore.

Anyone 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: 1303
Joined: Tue Jul 21, 2009 08:12 AM

Re: Internal and external IP

Posted: Tue Apr 19, 2016 02:19 PM
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM

Re: Internal and external IP

Posted: Tue Apr 19, 2016 02:28 PM
http://www.marcoboschi.it/indirizzo.asp


this is a little asp that returns only three variables

Code (fw): Select all Collapse
<%
Dim cIp
Dim cHost
Dim cLocal


cIp    = Request.ServerVariables( "REMOTE_ADDR" )
cLocal = Request.ServerVariables( "LOCAL_ADDR" )
cHost  = Request.ServerVariables( "REMOTE_HOST" )
Response.write "REMOTE_ADDR: " &cIp
Response.write "<br>"

Response.write "LOCAL_ADDR: " &cLocal
Response.write "<br>"

Response.write "REMOTE_HOST: " &cHost
Response.write "<br>"


%>
Marco Boschi
info@marcoboschi.it
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM

Re: Internal and external IP

Posted: Wed Apr 20, 2016 08:42 AM
driessen wrote:Until a short while ago, it use to work just fine. Now it doesn't work anymore.

Anyone any idea?


Because this address is no longer valid:

http://www.dnsstuff.com/docs/ipall

That's why it's better not to rely to external resources.

EMG
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM

Re: Internal and external IP

Posted: Wed Apr 20, 2016 03:55 PM

Guys,

Thanks a lot for your 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: 1467
Joined: Mon Oct 10, 2005 11:26 AM

Re: Internal and external IP

Posted: Fri Mar 01, 2019 01:19 PM
Hello,

Just like happened 3 years ago, this source is not working anymore.
Code (fw): Select all Collapse
WsaStartUp()
cVar1 := GetHostByName( GetHostName() )
WsaCleanUp()
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET","http://www.dnsstuff.com/docs",.f.)
oHttp:Send()
cVar2 := oHttp:ResponseText()
cVar2 := StrExtract(cVar2,"Your IP Address: <strong class="+CHR(34)+"ipBlock"+CHR(34)+">","</strong>")
Until a few weeks ago, it worked just fine. Now I get an 404 error.

Does anyone have any alternative?

Thanks a lot in advance.

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: Internal and external IP

Posted: Fri Mar 01, 2019 01:34 PM
Code (fw): Select all Collapse
http://forums.fivetechsupport.com/viewtopic.php?f=3&t=15742&p=81532&hilit=StrExtract#p81532

#include "FiveWin.ch"

Function MyWanIP()

   local oHttp, cHtml

   oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
   oHttp:Open( "GET", "http://www.ip-adress.com/", .f. )
   oHttp:Send()

   cHtml := oHttp:ResponseText()

   cHtml := StrExtract( cHtml, "My IP address: ", "</h2>" )

   msginfo( cHtml )

Return( cHtml )

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
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM

Re: Internal and external IP

Posted: Fri Mar 01, 2019 05:40 PM

Thanks a lot for trying to help me.
I got this message : "The requested resource is no longer available on this server and there is nog forwarding address".

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: 6755
Joined: Wed Feb 15, 2012 08:25 PM

Re: Internal and external IP

Posted: Fri Mar 01, 2019 09:09 PM
Try

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

Function TipExternalIP()

   local cUrl       := "http://checkip.dyndns.com/"
   local oURL       := TUrl():New( cUrl )
   local oClient    := TIpClientHttp():New( oUrl )
   local cJson
   local nPos1
   local nPos2
   local cIp

   if oClient:Open()   
      cJson := oClient:ReadAll()
      //? cJson
      nPos1 := At( ":", cJson )
      nPos2 := Rat( "</body>", cJson )
      cIp   := AllTrim( Substr( cJson, nPos1 + 1, Len( cJson ) - ( nPos2 + 5 ) ) )
      oClient:Close()
   endif

Return cIp

//----------------------------------------------------------------------------//


or try with this URL with your code ( CreateObject )
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Internal and external IP

Posted: Fri Mar 01, 2019 09:12 PM
Michael,

You may place this little PHP at your server:

getip.php
Code (fw): Select all Collapse
<?php
  echo $_SERVER[ 'REMOTE_ADDR' ];
?>


I have copied it in FiveTech server, so please replace "http://www.ip-adress.com/" with "http://www.fivetechsoft.com/getip.php"
in your code and try it

Click on this to check your IP:
http://www.fivetechsoft.com/getip.php
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM

Re: Internal and external IP

Posted: Sat Mar 02, 2019 09:21 AM

Antonio,

You are the best.

Thanks a lot for your help.

Problem solved.

Have a nice weekend.

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: 1387
Joined: Fri May 23, 2008 01:33 PM

Re: Internal and external IP - solved

Posted: Sat Mar 02, 2019 12:03 PM
getip.asp
Code (fw): Select all Collapse
<html>
<body>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</body>
</html>
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06

Continue the discussion