Search code examples
delphiipexternal

How to get external (public) IP in Delphi


I need to get my external (public) IP address from Delphi.

The same IP that is shown by www.whatismyip.com for example.

How can I do that ? Winsock doesn't allow this.


Solution

  • I don't think you can. Well, you could call some service that tells you what your IP address appears to be, ( ex: http://www.whatismyip.com/ ) and figure it out from the response. But I don't think anything on your PC will be able to tell you what your IP address looks like, to the outside world.

    Untested, but I think you can do this with Indy:

    MyPublicIP := IdHTTP1.Get('http://automation.whatismyip.com/n09230945.asp');
    

    Please review the rules/policy at: http://www.whatismyip.com/faq/automation.asp before using this.