コード例 #1
0
        internal static string ToSerializedValue(this HostNameType value)
        {
            switch (value)
            {
            case HostNameType.Verified:
                return("Verified");

            case HostNameType.Managed:
                return("Managed");
            }
            return(null);
        }
コード例 #2
0
    public static IPAddress GetLocalIp(HostNameType hostNameType)
    {
        var internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

        if (internetConnectionProfile?.NetworkAdapter == null)
        {
            return(null);
        }
        var hostname =
            NetworkInformation.GetHostNames()
            .FirstOrDefault(
                hostName =>
                hostName.Type == hostNameType &&
                hostName.IPInformation?.NetworkAdapter != null &&
                hostName.IPInformation.NetworkAdapter.NetworkAdapterId == internetConnectionProfile.NetworkAdapter.NetworkAdapterId);

        // the ip address
        return(IPAddress.Parse(hostname?.CanonicalName));
    }
コード例 #3
0
        public static string GetLocalIp(HostNameType hostNameType = HostNameType.Ipv4) //https://stackoverflow.com/questions/33770429/how-do-i-find-the-local-ip-address-on-a-win-10-uwp-project
        {
            var icp = NetworkInformation.GetInternetConnectionProfile();

            if (icp?.NetworkAdapter == null)
            {
                return(null);
            }
            var hostname =
                NetworkInformation.GetHostNames()
                .FirstOrDefault(
                    hn =>
                    hn.Type == hostNameType &&
                    hn.IPInformation?.NetworkAdapter != null &&
                    hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId);

            // the ip address
            return(hostname?.CanonicalName);
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: MechaniUm/RoboShell
        public static string GetLocalIp(HostNameType hostNameType = HostNameType.Ipv4)
        {
            var icp = NetworkInformation.GetInternetConnectionProfile();

            if (icp?.NetworkAdapter == null)
            {
                return(null);
            }
            var hostname =
                NetworkInformation.GetHostNames()
                .FirstOrDefault(
                    hn =>
                    hn.Type == hostNameType &&
                    hn.IPInformation?.NetworkAdapter != null &&
                    hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId);

            // the ip address
            return(hostname?.CanonicalName);
        }
コード例 #5
0
ファイル: NameUtil.cs プロジェクト: gustavnilsson14/ldjam48
    public string GetHostName()
    {
        Array values = Enum.GetValues(typeof(HostNameType));

        System.Random random   = new System.Random();
        HostNameType  nameType = (HostNameType)values.GetValue(random.Next(values.Length));
        List <string> result   = new List <string>();

        switch (nameType)
        {
        case HostNameType.OS_USAGE_OWNER:
            result.AddRange(new List <string>()
            {
                RandomFromList(hostOs), RandomFromList(hostUsage), RandomFromList(hostOwner)
            });
            break;

        case HostNameType.OWNER_OS:
            result.AddRange(new List <string>()
            {
                RandomFromList(hostOwner), RandomFromList(hostOs)
            });
            break;

        case HostNameType.OWNER_USAGE:
            result.AddRange(new List <string>()
            {
                RandomFromList(hostOwner), RandomFromList(hostUsage)
            });
            break;

        case HostNameType.USAGE_OS:
            result.AddRange(new List <string>()
            {
                RandomFromList(hostUsage), RandomFromList(hostOs)
            });
            break;

        default:
            break;
        }
        return(string.Join("-", result));
    }
コード例 #6
0
        private static string GetNetworkIdentifier(HostNameType hostNameType = HostNameType.Ipv4)
        {
            var icp = NetworkInformation.GetInternetConnectionProfile();

            if (icp?.NetworkAdapter == null)
            {
                return(null);
            }

            var hostname =
                NetworkInformation.GetHostNames()
                .FirstOrDefault(
                    hn =>
                    hn.Type == hostNameType &&
                    hn.IPInformation?.NetworkAdapter != null &&
                    hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId);

            // the ip address
            return(hostname?.CanonicalName.Substring(0, hostname.CanonicalName.LastIndexOf('.') + 1));
        }
コード例 #7
0
 public static string ToSerialString(this HostNameType value) => value switch
 {
コード例 #8
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="HostNameType" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => HostNameType.CreateFrom(sourceValue);