Internal and external IP - solved

Internal and external IP - solved

Postby driessen » Tue Apr 19, 2016 2:12 pm

Hello,

I used to use this code to get my internal and externam IP :
Code: Select all  Expand view
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.
Last edited by driessen on Sat Mar 02, 2019 9:21 am, edited 1 time 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: Internal and external IP

Postby lucasdebeltran » Tue Apr 19, 2016 2: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Internal and external IP

Postby MarcoBoschi » Tue Apr 19, 2016 2:28 pm

http://www.marcoboschi.it/indirizzo.asp


this is a little asp that returns only three variables

Code: Select all  Expand view

<%
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>"


%>
 
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Internal and external IP

Postby Enrico Maria Giordano » Wed Apr 20, 2016 8: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
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Internal and external IP

Postby driessen » Wed Apr 20, 2016 3:55 pm

Guys,

Thanks a lot for your 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

Postby driessen » Fri Mar 01, 2019 1:19 pm

Hello,

Just like happened 3 years ago, this source is not working anymore.
Code: Select all  Expand view
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. 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

Postby karinha » Fri Mar 01, 2019 1:34 pm

Code: Select all  Expand view

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

Re: Internal and external IP

Postby driessen » Fri Mar 01, 2019 5: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. 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

Postby cnavarro » Fri Mar 01, 2019 9:09 pm

Try

Code: Select all  Expand view

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

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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Internal and external IP

Postby Antonio Linares » Fri Mar 01, 2019 9:12 pm

Michael,

You may place this little PHP at your server:

getip.php
Code: Select all  Expand view
<?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
User avatar
Antonio Linares
Site Admin
 
Posts: 42085
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Internal and external IP

Postby driessen » Sat Mar 02, 2019 9: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. 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 - solved

Postby Horizon » Sat Mar 02, 2019 12:03 pm

getip.asp
Code: Select all  Expand view
<html>
<body>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</body>
</html>
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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