using Raspberry Pi 2. have Windows Iot installed.

I am trying to get the devices DHCP address via my C# code.

At the moment I have this:

 var hostName = NetworkInformation.GetHostNames();

Whilst I can read the 'DisplayName' but the IP Address Info is always null?


You may need to use this code

public IPAddress GetIPAddress()
   List<string> IpAddress = new List<string>();
   var Hosts = Windows.Networking.Connectivity.NetworkInformation.GetHostNames().ToList();
   foreach (var Host in Hosts)
      string IP = Host.DisplayName;
   IPAddress address = IPAddress.Parse(IpAddress.Last());
   return address;
  • Hi, I upgraded to IoT Windows 10 Build 10586 and now the broadcasts are not received. Has this new OS version got a firewall somewhere now?
    – user11286
    Jan 15 '16 at 17:50
  • Hi. Not sure mate. Please ask a new question. I will inspect. Check if u can ping the port 80 and your in question.
    – Piotr Kula
    Jan 15 '16 at 17:52

Upgraded ppumkin code to return ipv4 address if exists. Returns null if disconnected or not available. (the original code returns ipv6 for me on rasberry pi 3)

    using Windows.Networking.Connectivity;

    public IPAddress GetIpAddress()
        var hosts = NetworkInformation.GetHostNames();
        foreach (var host in hosts)
            IPAddress addr;
            if (!IPAddress.TryParse(host.DisplayName, out addr)) continue;
            if (addr.AddressFamily != AddressFamily.InterNetwork) continue;
            return addr;
        return null;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy