ipalibaba-cloudalibaba-cloud-ecs

Programatically determine public IP of a ECS server in Alibaba Cloud (ALIYUN)


My application (C++) runs on an ECS server inside the Alibaba Cloud.

It needs to know its public address, but on the network only the private IPS is visible (similar to AWS, Google Cloud etc.)

Is there a way to automatically detect the public IP ?


Solution

  • There are several methods to determine your public IP address:

    1. Use an external source that returns your IP address. A Google search will turn up lots of sources. AWS has one: http://checkip.amazonaws.com/. You can make an HTTP request to that endpoint and parse the result. Use a reliable vendor that just returns your IP address and not a bunch of formatted HTML statements.
    2. Look up your public IP in your ECS instance's metadata. This link has more information: ECS Metadata
    3. Use the Alibaba Cloud C++ SDK to call the ECS API Describe Instances Alibaba Cloud C++ SDK