Get hostname/IP for android device?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ondesic

I can get the host name for Windows using:


I know in other platforms you can use "HOSTNAME instead of “COMPUTERNAME”.

By using this I can get the IP address of the computer:

IP.resolve_hostname(OS.get_environment("COMPUTERNAME"), 1)

However, I cant for the life of me figure out the word to use in the get_environment() function to get the android Hostname to then get the IP address of the phone.

Does anyone know the environment name that holds the android hostname?

:bust_in_silhouette: Reply From: stan.wick.52

You can get the hostname of your android device using

OS.execute("getprop" , ["net.hostname"] , false)

That’ll output an array containing the host name, which you can then convert to a string.
I’m not close to my PC currently so I can’t test this, but it should be a start.

I tried this, but there are some problems.

  1. OS.Execute() only returns an “int” not and array.
  2. if I add the code:
var output = [];
OS.execute("getprop" , new[]{"net.hostname"} , false, output);

I get an empty array for “output”

ondesic | 2023-02-24 16:43

Sorry I didn’t specify the output array.
The issue though, is from android, or rather the difference in manufacturer implementation. Because on my device, it returns the hostname as expected, meanwhile, on another device, it returns an empty array because the net.hostname property is not set on that device.

stan.wick.52 | 2023-02-26 15:36