Getting device PUBLIC ip address

Hello,

I’m currently querying the balena supervisor from within a container and getting back a sensible response for device info:

[Logs]    [3/25/2022, 10:18:13 AM] [beacon] Device Information:
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] api_port: 48484
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] ip_address: 192.168.1.168
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] os_version: balenaOS 2.87.16+rev1
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] mac_address: DC:A6:32:7D:48:F7 DC:A6:32:7D:48:F9
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] supervisor_version: 12.11.0
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] update_pending: False
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] update_failed: False
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] update_downloaded: False
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] commit: localrelease
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] status: Idle
[Logs]    [3/25/2022, 10:18:13 AM] [beacon] download_progress: None

My main aim here is in getting the public-facing IP address, not the local one (as is returned in this case). On the dashboard, I see the device has the correct public IP displayed of the network it’s connected on. Does anyone know how to best get this info?

Cheers :beers:

How do you know you have one?

I.e. you are on an internal subnet. Do you have a guarantee that you can talk to the outside world? If your internal subnet has no default route to get to the outside, then you wouldn’t have an external addr.

Also, depending on your setup, you might have a different external address next time you log in.

Simplistic answer:
What happens if you try a traceroute to something like http://www.google.com
when it bounces back a ping, wouldn’t it bounce it to your public IP?

Really depends on how your network is setup. Sorry I don’t know more…

Yes, you can assume a public IP exists.

There are ways to query via the console rather than relying on the Supervisor. It’s quite Googleable as it’s not a Balena specific thing you are trying to do. First thing that springs to mind is curl ifconfig.me

Cheers, yes I ended up curling exactly this