Bom dia pessoal,
Tenho uma função aqui para retornar o IP externo. Segue abaixo o código:
******************
function IpExterno
******************
local cBuffer, cRequest, cResponse, nBytes, pSocket
HB_INetInit()
pSocket := HB_INetcreate( 3 ) // cria socket com 3 segundos de timeout
pSocket := HB_INetConnect( "checkip.dyndns.org", 80 ) && , pSocket )
if HB_INetErrorCode( pSocket ) <> 0
msgstop( "Socket error:" + sl_tostring( HB_INetErrorDesc( pSocket ) ) )
HB_INetCleanUp()
return "ERRO"
endif
nBytes := HB_INetSend( pSocket, "GET / HTTP/1.1" + CRLF + "Host: checkip.dyndns.org" + CRLF + "User-Agent: HTTP-Test-Program" + CRLF + CRLF )
cBuffer := space(512)
cResponse := ""
do while nBytes > 0
nBytes := HB_INetRecv( pSocket, @cBuffer )
cResponse += left( cBuffer, nBytes )
cBuffer := space(512)
enddo
HB_INetClose( pSocket )
HB_INetCleanUp()
return allTrim( substr( substr( cResponse, rat( "<body>", cResponse ) + 26 ), 1, At( "<", substr( cResponse, rat( "<body>", cResponse ) + 26 ) ) - 1 ) )
Espero que possa lhe ser útil.
T+
Rossine.
Rossine.
Harbour 3.4, MingW / Msvc, QT, Qt5xhb, GtQtc, DbfCdx, MySql/MariaDB.