FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour saber cual es la IP Publica
Posts: 401
Joined: Thu Oct 06, 2005 10:15 PM
saber cual es la IP Publica
Posted: Thu Jun 17, 2010 03:56 PM
Probado con xHarbour

Code (fw): Select all Collapse
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

------------------------------------------------------

*/
Posts: 592
Joined: Tue Mar 14, 2006 11:34 PM
Re: saber cual es la IP Publica
Posted: Thu Jun 17, 2010 10:04 PM

Pablo,

Excelente !!!

Andaba buscando una funcion como esta.

Muchas gracias por el aporte.

Saludos

FWH 10.6 + xHarbour + Borland 582
Posts: 94
Joined: Tue Mar 28, 2006 04:09 PM
Re: saber cual es la IP Publica
Posted: Tue Jul 12, 2011 10:21 PM

Mis estimados, me sirvio en este momento muchisimo su aporte, ya que ando haciendo CGI's con xHarbour y mis clientes requieren de filtro por IP Publica, chistosamente busque las palabras claves dentro del foro y no me salio ninguna ocurrencia, busque en google "saber ip publica desde xharbour" y la primer ocurrencia que me dio fue este post...

Gracias Mil

LF

Luis Fernando Rubio Rubio
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: saber cual es la IP Publica
Posted: Mon Jan 09, 2017 02:23 PM

Gracias Pablo. Está mui lento... Saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: saber cual es la IP Publica
Posted: Tue Jan 10, 2017 04:45 PM
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "tip.ch"

FUNCTION RetPublicIP()

   LOCAL cPubIP := "", cxHtml := "", url, oUrl, oHttp, oErr

   url := "http://checkip.dyndns.org"

   try
      oUrl:=TUrl():New( url ) // From tip.lib
      oHttp := TipClientHttp():New( oUrl , .f. ) // From tip.lib
   catch oErr
      ? "Erro: "+oErr:Description
   end try

   Try
      oHttp:Open()
      cxHtml := oHttp:ReadAll() // Baixa todo o conteúdo do site.
      cPubIP := allTrim( substr( substr( cxHtml, rat( "<body>", cxHtml ) + 26 ), 1, At( "<", substr( cxHtml, rat( "<body>", cxHtml ) + 26 ) ) - 1 ) )
   catch oErr
      ? "Erro: "+oErr:Description
   End

   oHttp:Close()

   DeleteUrlCacheEntry(url) // Lipar Cache

   ? cPubIP

Return Nil

//----------------------------------------------------------------------------------------------------------------------//
DLL Function DeleteUrlCacheEntry(lpszUrlName AS STRING) AS LONG PASCAL FROM "DeleteUrlCacheEntryA" LIB "wininet.dll"
//----------------------------------------------------------------------------------------------------------------------//

// A DLL fica em c:\Windows\System32\wininet.dll


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion