public static HostInfo GetCurrentHostInfo() { var profile = NetworkInformation.GetInternetConnectionProfile(); if (profile == null || profile.NetworkAdapter == null) { return null; } var networkAdapterId = profile.NetworkAdapter.NetworkAdapterId; foreach (var hostName in NetworkInformation.GetHostNames()) { if (!IsCurrentIPv4Address(profile, hostName)) { continue; } IPAddress address; if (!IPAddress.TryParse(hostName.CanonicalName, out address)) { continue; } var result = new HostInfo(networkAdapterId, hostName, address); return result; } return null; }
public static ConnectionInfo GetConnectionInfo(HostInfo hostInfo) { if (hostInfo == null) { throw new ArgumentNullException("hostInfo"); } var network = new IPNetwork(hostInfo.Address, hostInfo.HostName.IPInformation.PrefixLength.Value); var result = new ConnectionInfo(hostInfo.Address, network); return result; }
public static ConnectionInfo GetConnectionInfo(HostInfo hostInfo) { if (hostInfo == null) { throw new ArgumentNullException("hostInfo"); } var network = new IPNetwork(hostInfo.Address, hostInfo.HostName.IPInformation.PrefixLength.Value); var result = new ConnectionInfo(hostInfo.Address, network); return(result); }