Ejemplo n.º 1
0
		public HostsItem(NetAddress ip, HostName host, string comment = "")
		{
			Enabled = true;
			IP = ip;
			Aliases = new HostAliases(host);
			Comment = comment ?? "";
			Valid = true;
		}
Ejemplo n.º 2
0
		public bool Equals(HostName host)
		{
			if ((object)host == null) return false;
			return host.Unicode == this.Unicode;
		}
Ejemplo n.º 3
0
        static void RunAddMode()
        {
            if (ArgsQueue.Count == 0)
            {
                throw new HostNotSpecifiedException();
            }
            HostAliases aliases      = new HostAliases();
            NetAddress  address_ipv4 = null;
            NetAddress  address_ipv6 = null;
            string      comment      = "";
            bool        in_comment   = false;

            while (ArgsQueue.Count > 0)
            {
                string arg = ArgsQueue.Dequeue();
                if (in_comment)
                {
                    comment += arg + " ";
                    continue;
                }
                if (arg.Length > 0 && arg[0] == '#')
                {
                    in_comment = true;
                    comment    = (arg.Length > 1) ? (arg.Substring(1) + " ") : "";
                    continue;
                }
                arg = arg.ToLower();
                var address_test = NetAddress.TryCreate(arg);
                if (address_test != null)
                {
                    if (address_test.Type == NetAddressType.IPv4)
                    {
                        address_ipv4 = address_test;
                    }
                    else
                    {
                        address_ipv6 = address_test;
                    }
                    continue;
                }
                var hostname_test = HostName.TryCreate(arg);
                if (hostname_test != null)
                {
                    aliases.Add(hostname_test);
                    continue;
                }
                throw new Exception(String.Format("Unknown argument '{0}'", arg));
            }

            if (address_ipv4 == null && address_ipv6 == null)
            {
                address_ipv4 = new NetAddress("127.0.0.1");
            }

            if (address_ipv4 != null)
            {
                AddHostsItem(address_ipv4, aliases, comment.Trim());
            }

            if (address_ipv6 != null)
            {
                AddHostsItem(address_ipv6, aliases, comment.Trim());
            }
        }
Ejemplo n.º 4
0
 public int RemoveLinesWithHost(HostName host)
 {
     return(this.RemoveAll(item => item.Valid && item.Aliases.Contains(host)));
 }
Ejemplo n.º 5
0
 public int RemoveLinesWithHost(HostName host, NetAddressType type)
 {
     return(this.RemoveAll(item => item.Valid && (type == NetAddressType.None || item.IP.Type == type) && item.Aliases.Contains(host)));
 }
Ejemplo n.º 6
0
 public bool Equals(string host)
 {
     return(Equals(HostName.TryCreate(host)));
 }