Child pages
  • WHM API 1 Functions - get_public_ip
Skip to end of metadata
Go to start of metadata

Description

This function returns the public IP address for a specified public or private IP address. You can use this function to determine the system's main public IP address, especially for systems that use a 1:1 NAT configuration.

  • cPanel & WHM uses the main public IP address to perform many different functions. For example, the system uses this IP address to verify the server's license status with cPanel, Inc.
  • System administrators can configure the main public IP address in WHM's Basic WebHost Manager Setup interface (Home >> Server Configuration >> Basic WebHost Manager Setup). 

Examples  


 JSON API
https://hostname.example.com:2087/cpsess##########/json-api/get_public_ip?api.version=1&ip=1.2.3.4
 XML API
https://hostname.example.com:2087/cpsess##########/xml-api/get_public_ip?api.version=1&ip=1.2.3.4
 Command Line
whmapi1 get_public_ip ip=1.2.3.4


Notes:

  • You must URI-encode values.
  • For more information and additional output options, read our Guide to WHM API 1 documentation or run the whmapi1 --help command.
  • If you run CloudLinux™, you must use the full path of the whmapi1 command:

    /usr/local/cpanel/bin/whmapi1

 Output (JSON)
{
  "data": {
      "public_ip": "1.2.3.4"
  },
  "metadata": {
    "command": "get_public_ip",
    "reason": "OK",
    "result": 1,
    "version": 1
  }
}
 Output (XML)
<result>
    <data>
        <public_ip>1.2.3.4</public_ip>
    </data>
    <metadata>
        <version>1</version>
        <reason>OK</reason>
        <result>1</result>
        <command>get_public_ip</command>
    </metadata>
</result>


Note:

Use WHM's API Shell interface (WHM >> Home >> Development >> API Shell) to directly test WHM API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
ipstring

Required

The IP address to query.

  • A valid public IPv4 address, to return that IP address.
  • A valid private IPv4 address, to return the associated public IP address (for example, for 1:1 NAT systems).
1.2.3.4

 

Return

ReturnTypeDescriptionPossible valuesExample
public_ipstring

The public IP address.

A valid public IPv4 address.
1.2.3.4