Jump to content
Fivewin Brasil

IP Público


kapiaba

Recommended Posts

saber o IP PUBLICO:

#include "FiveWin.ch"
	static oWnd
	Function Main()
	   LOCAL nRetIp
	   nRetIp := PublicIP()
	Return Nil
	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)
      SYSREFRESH()
   ENDDO
	   ? cResponse
	   INetClose( pSocket )
   INetCleanUp()
	Return( allTrim( substr( substr( cResponse, rat( "<body>", cResponse ) + 26 ), 1, At( "<", substr( cResponse, rat( "<body>", cResponse ) + 26 ) ) - 1 ) ) )
Link to comment
Share on other sites

Ótima dica.

Comigo só funcionou assim:


#include "tip.ch"

FUNCTION RetPublicIP()
   LOCAL cPubIP := "", cxHtml := ""
   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

 

Link to comment
Share on other sites

Ariston, nem o Harbour e nem o xharbour, reconhecem esta FUNCTION.

Error: Unresolved external '_HB_FUN_DELETEURLCACHEENTRY' referenced from C:\FWH1612\SAMPLES\IPPUBLIC.OBJ
Error: Unable to perform link


#include "FiveWin.ch"
#include "tip.ch" // harbour nao tem este TIP.CH xHarbour tem. ????
	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


Link to comment
Share on other sites

Segue:

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

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

Link to comment
Share on other sites

Agora foi, many thanks!!

#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 - Ariston Santos


Link to comment
Share on other sites

Uso esta função:

FUNCTION PublicIP
LOCAL cUrl
LOCAL cIpEx

curl_global_init()
IF !empty( cUrl := curl_easy_init() )
    curl_easy_setopt( cUrl, HB_CURLOPT_DOWNLOAD )
    curl_easy_setopt( cUrl, HB_CURLOPT_URL, "http://checkip.dyndns.org" )
    curl_easy_setopt( cUrl, HB_CURLOPT_DL_BUFF_SETUP )
    curl_easy_perform( cUrl )
    cIpEx := curl_easy_dl_buff_get( cUrl )
    cIpEx := subStr( cIpEx, at( ":", cIpEx ) + 1 )
    cIpEx := subStr( cIpEx, 1, at( "<", cIpEx ) - 1 )
    msgInfo( "Seu IP externo é:" + cIpEx )
    curl_easy_cleanup( cUrl )
ENDIF
curl_global_cleanup()
RETURN cIpEx

Link to comment
Share on other sites

Está faltando algo ou alguma coisa:

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ FiveWin for Harbour 16.12 - Dec.  2016          Harbour development power  ³Ü
³ (c) FiveTech 1993-2016 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 ³Û
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
Compiling...
Harbour 3.2.0dev (r1603082110)
Copyright (c) 1999-2016, http://harbour-project.org/
Compiling 'IPPUBLI2.prg' and generating preprocessed output to 'IPPUBLI2.ppo'...
	Lines 4670, Functions/Procedures 1
Generating C source output to 'IPPUBLI2.c'... Done.
	IPPUBLI2.prg(12) Warning W0001  Ambiguous reference 'HB_CURLOPT_DOWNLOAD'
	IPPUBLI2.prg(13) Warning W0001  Ambiguous reference 'HB_CURLOPT_URL'
	IPPUBLI2.prg(14) Warning W0001  Ambiguous reference 'HB_CURLOPT_DL_BUFF_SETUP'
Embarcadero C++ 7.00 for Win32 Copyright (c) 1993-2015 Embarcadero Technologies, Inc.
IPPUBLI2.c:
Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
Error: Unresolved external '_HB_FUN_CURL_GLOBAL_INIT' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_INIT' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_SETOPT' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_PERFORM' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_DL_BUFF_GET' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_CLEANUP' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unresolved external '_HB_FUN_CURL_GLOBAL_CLEANUP' referenced from C:\FWH1612\SAMPLES\IPPUBLI2.OBJ
Error: Unable to perform link
* Linking errors *


Link to comment
Share on other sites

  • 4 months later...

#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 - Ariston Santos
	
/*
#include "FiveWin.ch"
	static oWnd
	Function Main()
	   LOCAL nRetIp
	   nRetIp := PublicIP()
	Return Nil
	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)
      SYSREFRESH()
   ENDDO
	   ? cResponse
	   INetClose( pSocket )
   INetCleanUp()
	Return( allTrim( substr( substr( cResponse, rat( "<body>", cResponse ) + 26 ), 1, At( "<", substr( cResponse, rat( "<body>", cResponse ) + 26 ) ) - 1 ) ) )
*/


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...