kapiaba Posted January 9, 2017 Report Share Posted January 9, 2017 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 ) ) ) Quote Link to comment Share on other sites More sharing options...
Ariston Santos Posted January 9, 2017 Report Share Posted January 9, 2017 Ó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 kapiaba 1 Quote Link to comment Share on other sites More sharing options...
kapiaba Posted January 10, 2017 Author Report Share Posted January 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
Ariston Santos Posted January 10, 2017 Report Share Posted January 10, 2017 Segue: //----------------------------------------------------------------------------------------------------------------------// DLL Function DeleteUrlCacheEntry(lpszUrlName AS STRING) AS LONG PASCAL FROM "DeleteUrlCacheEntryA" LIB "wininet.dll" //----------------------------------------------------------------------------------------------------------------------// A DLL fica em c:\Windows\System32\wininet.dll kapiaba 1 Quote Link to comment Share on other sites More sharing options...
kapiaba Posted January 10, 2017 Author Report Share Posted January 10, 2017 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 Ariston Santos 1 Quote Link to comment Share on other sites More sharing options...
ADutheil Posted January 12, 2017 Report Share Posted January 12, 2017 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 Quote Link to comment Share on other sites More sharing options...
kapiaba Posted January 12, 2017 Author Report Share Posted January 12, 2017 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 * Quote Link to comment Share on other sites More sharing options...
ADutheil Posted January 13, 2017 Report Share Posted January 13, 2017 Precisa linkar as libs hbcurl e libcurl. Quote Link to comment Share on other sites More sharing options...
Edu Posted June 9, 2017 Report Share Posted June 9, 2017 ADutheil, linkei a libcurl.lib no projeto e efetuei #include "hbcurl.ch" mas não consigo compilar. O que está faltando? Quote Link to comment Share on other sites More sharing options...
kapiaba Posted June 9, 2017 Author Report Share Posted June 9, 2017 #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 ) ) ) */ Quote Link to comment Share on other sites More sharing options...
ADutheil Posted June 11, 2017 Report Share Posted June 11, 2017 ADutheil, linkei a libcurl.lib no projeto e efetuei #include "hbcurl.ch" mas não consigo compilar. O que está faltando? Falta a hbcurl Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.