Notifications
Clear all

How to get Unicast Dns and Gateway Address in UWP

RSS

(@ganesh)
Noble Member
Joined: 2 years ago
Posts: 1362
14/05/2021 10:06 am

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?


Quote
(@ganesh)
Noble Member
Joined: 2 years ago
Posts: 1362
14/05/2021 10:08 am

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

publicstaticstringGetDirectConnectionName(){varicp=NetworkInformation.GetInternetConnectionProfile();if(icp!=null){if(icp.NetworkAdapter.IanaInterfaceType==EthernetIanaType){returnicp.ProfileName;}}returnnull;}publicstaticstringGetCurrentNetworkName(){varicp=NetworkInformation.GetInternetConnectionProfile();if(icp!=null){returnicp.ProfileName;}varresourceLoader=ResourceLoader.GetForCurrentView();varmsg=resourceLoader.GetString("NoInternetConnection");returnmsg;}publicstaticstringGetCurrentIpv4Address(){varicp=NetworkInformation.GetInternetConnectionProfile();if(icp!=null&&icp.NetworkAdapter!=null&&icp.NetworkAdapter.NetworkAdapterId!=null){varname=icp.ProfileName;varhostnames=NetworkInformation.GetHostNames();foreach(varhninhostnames){if(hn.IPInformation!=null&&hn.IPInformation.NetworkAdapter!=null&&hn.IPInformation.NetworkAdapter.NetworkAdapterId!=null&&hn.IPInformation.NetworkAdapter.NetworkAdapterId==icp.NetworkAdapter.NetworkAdapterId&&hn.Type==HostNameType.Ipv4){returnhn.CanonicalName;}}}varresourceLoader=ResourceLoader.GetForCurrentView();varmsg=resourceLoader.GetString("NoInternetConnection");returnmsg;}

ReplyQuote
Share:
Baidu