Local IP adress in UNet

I need to get local IP address. Is it possible?

I already solved my question with this method:

public string LocalIPAddress()
		IPHostEntry host;
		string localIP = "";
		host = Dns.GetHostEntry(Dns.GetHostName());
		foreach (IPAddress ip in host.AddressList)
			if (ip.AddressFamily == AddressFamily.InterNetwork)
				localIP = ip.ToString();
		return localIP;

return Network.player.ipAddress;

Even easier :wink:


In 2018.2 Network.player.ipAddress is no longer available.

I’ve found this and from a few tests it seems to work:

string hostName = System.Net.Dns.GetHostName();
string localIP = System.Net.Dns.GetHostEntry(hostName).AddressList[0].ToString();

Edited: now using GetHostEntry instead of GetHostByName because it’s obsolete warning CS0618.