How to get Unicast, Dns and Gateway Address in UWP?

0 votes
I'm trying to find Unicast, Dns and Gateway Address in windows IOT. Normally I can access these values with NetworkInterface.GetAllNetworkInterfaces() method.

But in UWP, that method is missing.

Is there any alternative for getting these values?
Jul 17, 2018 in IoT (Internet of Things) by Matt
• 2,260 points
113 views

1 answer to this question.

0 votes

Try this code Snippet I found here: https://social.msdn.microsoft.com/Forums/en-US/27a8b7a8-8071-4bc1-bbd4-e7c1fc2bd8d7/windows-10-iot-core-how-do-you-create-a-tcp-server-and-client?forum=WindowsIoT

    public static string GetDirectConnectionName()
    {
        var icp = NetworkInformation.GetInternetConnectionProfile();
        if (icp != null)
        {
            if(icp.NetworkAdapter.IanaInterfaceType == EthernetIanaType)
            {
                return icp.ProfileName;
            }
        }

        return null;
    }

    public static string GetCurrentNetworkName()
    {
        var icp = NetworkInformation.GetInternetConnectionProfile();
        if (icp != null)
        {
            return icp.ProfileName;
        }

        var resourceLoader = ResourceLoader.GetForCurrentView();
        var msg = resourceLoader.GetString("NoInternetConnection");
        return msg;
    }

    public static string GetCurrentIpv4Address()
    {
        var icp = NetworkInformation.GetInternetConnectionProfile();
        if (icp != null && icp.NetworkAdapter != null && icp.NetworkAdapter.NetworkAdapterId != null)
        {
            var name = icp.ProfileName;

            var hostnames = NetworkInformation.GetHostNames();

            foreach (var hn in hostnames)
            {
                if (hn.IPInformation != null &&
                    hn.IPInformation.NetworkAdapter != null &&
                    hn.IPInformation.NetworkAdapter.NetworkAdapterId != null &&
                    hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId &&
                    hn.Type == HostNameType.Ipv4)
                {
                    return hn.CanonicalName;
                }
            }
        }

        var resourceLoader = ResourceLoader.GetForCurrentView();
        var msg = resourceLoader.GetString("NoInternetConnection");
        return msg;
    }
answered Jul 17, 2018 by anonymous2
• 4,260 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Finding the Unicast, DNS and Gateway Address in UWP

Try the PInvoke api methods from Iphlpapi.dll. ...READ MORE

answered Aug 20, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
44 views
0 votes
1 answer

How to read data from MQTT in Eclipse Paho?

You don't read data from a MQTT ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
58 views
0 votes
1 answer
0 votes
1 answer

How to detect presence of a device in a WiFi network?

Finding the mac-address would probably work. Basically, ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by Shubham
• 13,110 points
54 views
0 votes
1 answer

Send LoRa measures to Fiware IOT agent via MQTT

down vote I dont know if I understood ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
248 views
0 votes
0 answers

Mosquitto Secure MQTT connection

My Question is regarding TLS/SSL MQTT connection. ...READ MORE

Jul 23, 2018 in IoT (Internet of Things) by Matt
• 2,260 points
45 views
0 votes
1 answer

MQTT connection consumes less power

HTTP(S) doesn't keep a connection open - ...READ MORE

answered Jul 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
49 views
0 votes
1 answer

Difference between IoTivity and AllJoyn?

Architecturally, IoTivity had four fundametal units: Discovery, ...READ MORE

answered Sep 5, 2018 in IoT (Internet of Things) by DataKing99
• 8,100 points
107 views
0 votes
1 answer

How to connect Raspberry Pi and lighting the LED?

You might want to try instead to ...READ MORE

answered Jul 23, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
22 views