Finally made an API which displays the public IPv6 prefix and public IPv4 address using http://192.168.1.1/cgi-bin/public-ip.sh locally instead of querying a remote server.
upload the public-ip.sh file in /www/cgi-bin/ subdirectory with 755 permission.
#!/bin/sh
printf "Content-Type: text/plain\n\n"
ipv4=`ubus call network.interface.wan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';`
ipv6=`ubus call network.interface.wan6 status | grep \"ipv6-prefix\" -A 10 | grep \"address\" | grep -o '"[^"]\+"' | sed 's/"//g' | grep '^2' | head -n 1;`
echo "{"
echo " \"ipv4\": \"$ipv4\","
echo " \"ipv6\": \"$ipv6\""
echo "}"
exit 0
Or modify the script to just show public IP without the json format.
Let me know if any improvements can be made.