Beispiel #1
0
        public NetAddress(string ip)
        {
            if (ip == null)
            {
                throw new ArgumentNullException();
            }
            try
            {
                var parsed = IPAddress.Parse(ip);
                switch (parsed.AddressFamily)
                {
                case AddressFamily.InterNetwork:
                    Type = NetAddressType.IPv4;
                    IP   = parsed.ToString();
                    break;

                case AddressFamily.InterNetworkV6:
                    Type = NetAddressType.IPv6;
                    IP   = NormalizeIPv6(ip);
                    break;

                default: throw new Exception();
                }
            }
            catch
            {
                throw new FormatException(String.Format("Invalid IP address '{0}'", IP));
            }
        }
Beispiel #2
0
 public void Deserialize(BinaryReader reader)
 {
     AddressType = reader.Read <NetAddressType>();
     Address     = reader.ReadString(MediusConstants.NET_MAX_NETADDRESS_LENGTH);
     Port        = reader.ReadUInt32();
 }
Beispiel #3
0
		public NetAddress(string ip)
		{
			if (ip == null) throw new ArgumentNullException();
			try
			{
				var parsed = IPAddress.Parse(ip);
				switch (parsed.AddressFamily)
				{

					case AddressFamily.InterNetwork:
						Type = NetAddressType.IPv4;
						IP = parsed.ToString();
					break;

					case AddressFamily.InterNetworkV6:
						Type = NetAddressType.IPv6;
						IP = NormalizeIPv6(ip);
					break;

					default: throw new Exception();
				}
			}
			catch
			{
				throw new FormatException(String.Format("Invalid IP address '{0}'", IP));
			}
		}
Beispiel #4
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)));
 }