Probably something like: https://stackoverflow.com/a/65362666
The point being, you have to have something on the 'outside' reporting back what it sees as the IP address.
I use a home network of 3 desktop PCs interfacing with a ISP gateway, via a wifi router and several WIFI extenders, so the IP address obtained by the app in question has a lot of possible different answers:
what is the internal network IP addresses of the computer used to run the app, or any of my computers
what is the internal network IP address of the gateway
what are the internal network IP addresses of the router/extenders
what is the IP address used by the gateway to access the internet, seen by my ISP
do the router/extenders use dynamic or static IP addressing? Dynamic IP addressing really complicates how to get an IP address. For ease of maintenance I use static.
Another question that needs to be asked and answered:
is the IP address in IPv4 or IPv6?
To really add to the IP address mix I also have 2 networked printers and several tablet devices (iPad and Fire) that connect to the wireless WIFI on demand as well as two cell phones I can connect to WIFI when I want. Each of these devices have their own discrete IP address, available in IPv4 and IPv6 format, as well.
Lots of permutations to consider before even thinking about "how do I get an IP address when opening an app?"
@Ganado, my Gateway can report what IP address it uses to connect to my ISP, no need to "step outside" the network setup.