Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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);
        }