Unity 2018 logo

Unity – How to get local IP address

In Unity 2018 getting the player local IP address has changed. Previously we could use the UnityEngine.Network class, but it has become obsolete.

string ipAddress = UnityEngine.Network.player.ipaddress; // obsolete

After doing some research I found the C# way of getting the local IP address of the user:

public static class IPManager
    public static string GetLocalIPAddress()
        var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
        foreach (var ip in host.AddressList)
            if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                return ip.ToString();

        throw new System.Exception("No network adapters with an IPv4 address in the system!");

This can be used to start a local server or direct connect to one.

Before trying to get the IP, you can also check if you are connected with the following line:



Thanks to Mrchief: https://stackoverflow.com/questions/6803073/get-local-ip-address

Pierre Planeau

My name is Pierre and I run this website. You can learn more about me over here and some of my personal projects over there. 🙂

Other posts

  • COMMENTS (2)

    1. Patrick Machado 30th August 2019 at 04:15 -

      Very usefull thanks!

    2. ahmet 13th October 2018 at 02:35 -

      thanks pierre king ();


    Leave a Reply