Using API to get WAN ipv4 address

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.

Using API to get WAN ipv4 address

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.
Using API to get WAN ipv4 address
Using API to get WAN ipv4 address
2023-07-23 23:52:38 - last edited 2023-07-25 02:41:19
Tags: #API
Model: OC200   ER605 (TL-R605)  
Hardware Version:
Firmware Version:

 

Hi,

 

I am trying to use the API to get the external IP address of my router. Thus far I was able to log into the controller and get the full wan configuration with the script bellow:

 

 

CONTROLLER_ID="$(curl -sk "${OMADA_URL}/api/info" | jq -r .result.omadacId)"

TOKEN="$(curl -sk -X POST -c "${TOKEN_FILE}" -b "${TOKEN_FILE}" -H "Content-Type: application/json" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/login" -d '{"username": "'"${USERNAME}"'", "password": "'"${PASSWORD}"'"}' | jq -r .result.token)"

SITE_ID="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE}" | jq -r .result.id)"

echo $OMADA_URL
echo $CONTROLLER_ID
echo "SITE_ID= " $SITE_ID
echo $TOKEN

curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/loginStatus?token=${TOKEN}" | jq .

curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE_ID}/setting/wan/networks?token=${TOKEN}" | jq .
 

But I wasn`t able to get the external IP. I tried to look into this post (v5.9.9 API) but I wasn`t able to find any API call that would give that directly. 

 

I tried the following calls and couldn`t get the IP:

 

/{omadacId}/api/v2/sites/{siteId}/dashboard/portstatedetails

/{omadacId}/api/v2/sites/{siteId}/setting/wan/networks

/{omadacId}/api/v2/sites/{siteId}/setting/wanlanstatus

 

Is there an API call for that?

 

  0      
  0      
#1
Options
2 Accepted Solutions
Re:Using API to get WAN ipv4 address-Solution
2023-07-24 08:06:03 - last edited 2023-07-25 02:41:19

Hello @GRALVES,

 

Please refer to this command:

https://[controller_ip]:8043/[controller_id]/api/v2/sites/[site_id]/gateways/AC-15-A2-87-66-14 [device mac address]

Best Regards! >> Omada EAP Firmware Trial Available Here << >> Get the Latest Omada SDN Controller Releases Here << *Try filtering posts on each forum by Label of [Early Access]*
Recommended Solution
  1  
  1  
#2
Options
Re:Using API to get WAN ipv4 address-Solution
2023-07-24 23:33:52 - last edited 2023-07-25 02:43:02

  @Hank21 worked perfeclty. Here is the code in case someone needs it in the future:

 

CONTROLLER_ID="$(curl -sk "${OMADA_URL}/api/info" | jq -r .result.omadacId)"

TOKEN="$(curl -sk -X POST -c "${TOKEN_FILE}" -b "${TOKEN_FILE}" -H "Content-Type: application/json" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/login" -d '{"username": "'"${USERNAME}"'", "password": "'"${PASSWORD}"'"}' | jq -r .result.token)"

SITE_ID="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE}" | jq -r .result.id)"


IPV4="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE_ID}/gateways/${GATEWAY}?token=${TOKEN}" | jq -r .result.portStats[1].wanPortIpv4Config.ip)"

IPV6="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE_ID}/gateways/${GATEWAY}?token=${TOKEN}" | jq -r .result.portStats[1].wanPortIpv6Config.addr)"

 

 

where 

OMADA_URL = URL of local controller

SITE = "default"

USERNAME and PASSWORD are self explanatory

TOKEN_FILE = location where the authentication token will be stored

GATEWAY = MAC address of the gateway, eg., XX-XX-XX-XX-XX-XX

 

Recommended Solution
  1  
  1  
#3
Options
3 Reply
Re:Using API to get WAN ipv4 address-Solution
2023-07-24 08:06:03 - last edited 2023-07-25 02:41:19

Hello @GRALVES,

 

Please refer to this command:

https://[controller_ip]:8043/[controller_id]/api/v2/sites/[site_id]/gateways/AC-15-A2-87-66-14 [device mac address]

Best Regards! >> Omada EAP Firmware Trial Available Here << >> Get the Latest Omada SDN Controller Releases Here << *Try filtering posts on each forum by Label of [Early Access]*
Recommended Solution
  1  
  1  
#2
Options
Re:Using API to get WAN ipv4 address-Solution
2023-07-24 23:33:52 - last edited 2023-07-25 02:43:02

  @Hank21 worked perfeclty. Here is the code in case someone needs it in the future:

 

CONTROLLER_ID="$(curl -sk "${OMADA_URL}/api/info" | jq -r .result.omadacId)"

TOKEN="$(curl -sk -X POST -c "${TOKEN_FILE}" -b "${TOKEN_FILE}" -H "Content-Type: application/json" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/login" -d '{"username": "'"${USERNAME}"'", "password": "'"${PASSWORD}"'"}' | jq -r .result.token)"

SITE_ID="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE}" | jq -r .result.id)"


IPV4="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE_ID}/gateways/${GATEWAY}?token=${TOKEN}" | jq -r .result.portStats[1].wanPortIpv4Config.ip)"

IPV6="$(curl -sk -X GET -b "${TOKEN_FILE}" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/sites/${SITE_ID}/gateways/${GATEWAY}?token=${TOKEN}" | jq -r .result.portStats[1].wanPortIpv6Config.addr)"

 

 

where 

OMADA_URL = URL of local controller

SITE = "default"

USERNAME and PASSWORD are self explanatory

TOKEN_FILE = location where the authentication token will be stored

GATEWAY = MAC address of the gateway, eg., XX-XX-XX-XX-XX-XX

 

Recommended Solution
  1  
  1  
#3
Options
Re:Using API to get WAN ipv4 address
2023-07-25 02:42:51

Hello @GRALVES,

 

Thank you for your valued feedback! Glad to hear that your concern was resolved finally.

Hope you enjoy the Internet with TP-Link products and have a great day!

Best Regards! >> Omada EAP Firmware Trial Available Here << >> Get the Latest Omada SDN Controller Releases Here << *Try filtering posts on each forum by Label of [Early Access]*
  0  
  0  
#4
Options

Information

Helpful: 0

Views: 1021

Replies: 3

Tags

Related Articles