https://stackoverflow.com/questions/47812879/how-to-programmatically-get-a-public-ip-address
You can make use of the web service from ipify.org
Read through the documentation here
Use https://api.ipify.org/?format=json WS to get device public IP address. This would output your IP address in JSON format.