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,270 points
1,221 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,240 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,130 points
915 views
0 votes
0 answers
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,240 points
944 views
+1 vote
1 answer
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,240 points
1,748 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,270 points
600 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,240 points
809 views
0 votes
1 answer

Difference between IoTivity and AllJoyn?

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

answered Sep 6, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,248 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,240 points
669 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP