Get IP on Android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PerduGames
:warning: Old Version Published before Godot 3 was released.

How do I get IP on Android? I’m trying with:

IP.get_local_addresses()

But it is not working.

Up 1:

I got it here, it’s some other mistake in the project, I’ll check it out. But in an empty project with just that, it worked correctly, the only problem is that it gives me an array, and I want to get the local ip ip4, and in android it stays in one position, and in the other debian, it has some better way or I’ll have to Check the platform on which I am and this will only change platform or device to device?

Make sure that you have INTERNET and ACCESS_NETWORK_STATE permissions.

timoschwarzer | 2017-07-24 04:24

It is working, the problem is that as I get an array that has the ips in different rows depending on the platform, which I hope is only platform, because if this switch from device to device will be more annoying to verify.

PerduGames | 2017-07-24 04:52

Just a guess, but I think you are getting the IP of every network interface present and/or enabled (cell data, Wi-Fi, etc.). Not sure about the enabled part, but the thing is that you have to expect a different number of results at least among devices.
With more info about your use case we may give you further advice.

RandomShaper | 2017-07-26 22:38

:bust_in_silhouette: Reply From: Marlon Henry Schweig

You receive an array of ip, referring to all as interfaces available without device. Remember that all ip’s are not valid outside of the LAN, since you are under a NAT network.

You need to verify that this network is within a private network standard:

  • 0.0.0.0/8 Internet * only you can use * - RFC 1700
  • 10.0.0.0/8 Private - RFC 1918
  • 14.0.0.0/8 Public - RFC 1700
  • 39.0.0.0/8 Reserved - RFC 1797
  • 127.0.0.0/8 Localhost - RFC 3330
  • 128.0.0.0/16 Reserved (IANA) - RFC 3330
  • 169.254.0.0/16 Zeroconf - RFC 3927
  • 172.16.0.0/12 Private network - RFC 1918
  • 191.255.0.0/16 Reserved (IANA) - RFC 3330
  • 192.0.2.0/24 Documentation - RFC 3330
  • 192.88.99.0/24 IPv6 for IPv4 - RFC 3068
  • 192.168.0.0/16 Private Network - RFC 1918
  • 198.18.0.0/15 Network Benchmark Test - RFC 2544
  • 223.255.255.0/24 Reserved - RFC 3330
  • 224.0.0.0/4 Multicasts - (former Class D network) RFC 3171
  • 240.0.0.0/4 Reserved - (former Class E network) RFC 1700
  • 255.255.255.255 Broadcast

Regex would be a great way to solve this problem, however I do not remember if GDScript contains something like this: /

You can solve it with some non-deterministic automata.