示例#1
0
        /// <summary>
        /// Maps the data from registry.
        /// </summary>
        /// <param name="card">The card.</param>
        internal static void MapDataFromRegistry(WindowsNetworkCard card)
        {
            RegistryKey regKey = null;

            string sKey = @"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + card.Id;

            try
            {
                regKey              = Registry.LocalMachine.OpenSubKey(sKey);
                card.IpAddress      = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "IPAddress");
                card.GatewayAddress = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DefaultGateway");
                card.SubnetMask     = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "SubnetMask");

                card.Dhcp = RegistryUtility.ReadIntValue(RegistryKeyType.LocalMachine, sKey, "EnableDhcp") == 1 ? true : false;

                string[] dns = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "NameServer").Split(',');

                if (dns.Length >= 1)
                {
                    card.Dns = dns[0];
                }
                if (dns.Length >= 2)
                {
                    card.Dns2 = dns[1];
                }

                card.CurrentIpAddress      = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpIPAddress");
                card.CurrentGatewayAddress = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpDefaultGateway");
                card.CurrentSubnetMask     = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpSubnetMask");

                string[] cdns = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpServer").Split(' ');

                if (cdns.Length >= 1)
                {
                    card.CurrentDns = cdns[0];
                }
                if (cdns.Length >= 2)
                {
                    card.CurrentDns2 = cdns[1];
                }
            }
            finally
            {
                if (regKey != null)
                {
                    regKey.Close();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Reads the config.
        /// </summary>
        /// <returns></returns>
        public static ProxyConfiguration ReadConfig()
        {
            ProxyConfiguration ret = new ProxyConfiguration();

            long tmp1 = RegistryUtility.ReadIntValue(RegistryKeyType.CurrentUser, RK_INTERNET_SETTINGS, "ProxyEnable", 0);

            if (tmp1.Equals(1))
            {
                ret.Enabled = true;
            }
            else
            {
                ret.Enabled = false;
            }

            string tmp2 = RegistryUtility.ReadStringValue(RegistryKeyType.CurrentUser, RK_INTERNET_SETTINGS, "ProxyServer");

            string[] aTmp2 = tmp2.Split(':');
            ret.ServerAddress = aTmp2[0];
            if (aTmp2.Length > 1)
            {
                ret.Port = Int32.Parse(aTmp2[1]);
            }


            string tmp3 = RegistryUtility.ReadStringValue(RegistryKeyType.CurrentUser, RK_INTERNET_SETTINGS, "ProxyOverride");

            if (tmp3.EndsWith(";<local>"))
            {
                ret.ProxyOverrideEnabled = true;
                tmp3 = tmp3.Substring(0, tmp3.IndexOf(";<local>") - 1);
                ret.ProxyOverride = tmp3;
            }
            else
            {
                ret.ProxyOverrideEnabled = false;
                ret.ProxyOverride        = tmp3;
            }


            return(ret);
        }