obter ip externo

45 views
Skip to first unread message

Ronaldo Geniais

unread,
Oct 30, 2025, 8:53:44 AM (16 hours ago) Oct 30
to Harbour Users
alguem sabe se é possivel obter o ip externo com alguma funcao ?

Maurício Faria

unread,
Oct 30, 2025, 9:58:50 AM (15 hours ago) Oct 30
to harbou...@googlegroups.com, Ronaldo Geniais
FUNCTION IpPublico()

 LOCAL cIpPublico := 'NIL'
 LOCAL oIp

 cIpPublico := "..."

 #ifndef __PLATFORM__LINUX
    TRY
       oIp := WIN_OLECREATEOBJECT("MSXML2.XMLHTTP")

       IF HB_ISOBJECT(oIp)
          oIp:OPEN("GET","https://api.ipify.org/",.F.)
          oIp:SEND()
          cIpPublico := LEFT(ALLTRIM(oIp:responseText),16)
       ENDIF
    CATCH
    END
 #endif
RETURN (cIpPublico)


[[]] Maurício Ventura Faria


Em 30/10/2025 09:53, Ronaldo Geniais escreveu:
alguem sabe se é possivel obter o ip externo com alguma funcao ? --
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/e4998a69-d2e1-41ac-81e3-528d341ea086n%40googlegroups.com.

ronald...@uol.com.br

unread,
Oct 30, 2025, 12:15:28 PM (13 hours ago) Oct 30
to Maurício Faria, harbou...@googlegroups.com
Mauricio
obrigado por compartilhar,
fiz o teste com o que me passou e funcionou.
Estranho que funcionou em um projeto e no outro nao,
estou tentando descobrir porque.
Tenho dois projetos na minigui extended, ajustei o codigo que 
voce me passou, em um dos projetos, funciona, mostra o ip publico,
ja em outro projeto, aparentemente com todas as libs e propriedades
iguais, nao retorna o ip publico.
Muto obrigado por compartilhar.
 

Geniais Soluções em Informatica
      Ronaldo Batista Lima 
      011-99154-9291 

      email : gen...@uol.com.br

 

 

Maurício Faria

unread,
Oct 30, 2025, 1:02:40 PM (12 hours ago) Oct 30
to ronald...@uol.com.br, harbou...@googlegroups.com
Ronaldo, boa tarde.
 
Pode ser algum erro que foi ignorado.
Experimente remover as linhas

    TRY
    CATCH
    END

E veja se dá algum erro.

[[]] Maurício Faria
Reply all
Reply to author
Forward
0 new messages