Skip to content

Instantly share code, notes, and snippets.

@kazuakix
Last active June 14, 2018 04:45
Show Gist options
  • Save kazuakix/929d024db6dc208ba9c8 to your computer and use it in GitHub Desktop.
Save kazuakix/929d024db6dc208ba9c8 to your computer and use it in GitHub Desktop.
public async void GetConnections()
{
var hostnames = new List<HostName>();
foreach (var hn in NetworkInformation.GetHostNames())
{
if (hn.IPInformation != null && hn.IPInformation.NetworkAdapter != null)
{
hostnames.Add(hn);
}
}
var f = new ConnectionProfileFilter
{
IsConnected = true
};
foreach (var cp in await NetworkInformation.FindConnectionProfilesAsync(f))
{
foreach(var hn in hostnames.Where(_ => _.IPInformation.NetworkAdapter.NetworkAdapterId == cp.NetworkAdapter.NetworkAdapterId))
{
Debug.WriteLine("--------------------------------------------------");
if (cp.IsWlanConnectionProfile) Debug.WriteLine( "Connection Type : WLAN");
else if (cp.IsWwanConnectionProfile) Debug.WriteLine("Connection Type : 3GPP");
Debug.WriteLine("Profile Name : " + cp.ProfileName);
Debug.WriteLine("IP Type : " + hn.Type);
Debug.WriteLine("IP Address : " + hn.DisplayName);
if (cp.IsWwanConnectionProfile)
{
Debug.WriteLine("Operator Name : " + cp.WwanConnectionProfileDetails.HomeProviderId);
Debug.WriteLine("APN Name : " + cp.WwanConnectionProfileDetails.AccessPointName);
}
// 接続状況
var cl = cp.GetNetworkConnectivityLevel();
Debug.WriteLine("Connectivity Level: " + cl);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment