Exemplo n.º 1
0
 public void ParseTest_IPv4_CIDR_Max()
 {
     var range = new IPAddressRange("219.165.64.73/32");
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("219.165.64.73");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("219.165.64.73");
 }
Exemplo n.º 2
0
 public void ParseTest_IPv4_Uniaddress()
 {
     var range = new IPAddressRange("192.168.60.13");
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("192.168.60.13");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("192.168.60.13");
 }
Exemplo n.º 3
0
 public void CtorTest()
 {
     var range = new IPAddressRange();
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("0.0.0.0");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("0.0.0.0");
 }
Exemplo n.º 4
0
 public void ParseTest_IPv4_Bitmask()
 {
     var range = new IPAddressRange("192.168.1.0/255.255.255.0");
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("192.168.1.0");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("192.168.1.255");
 }
 public void CtorTest_MaskLength()
 {
     var range = new IPAddressRange(IPAddress.Parse("192.168.0.80"), 24);
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("192.168.0.0");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("192.168.0.255");
 }
 public void CtorTest_Single()
 {
     var range = new IPAddressRange(IPAddress.Parse("192.168.0.88"));
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("192.168.0.88");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("192.168.0.88");
 }
Exemplo n.º 7
0
 public void ParseTest_IPv4_Bitmask()
 {
     var range = new IPAddressRange("219.165.64.0/19");
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("219.165.64.0");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("219.165.95.255");
 }
Exemplo n.º 8
0
 public void ParseTest_IPv4_Begin_to_End()
 {
     var range = new IPAddressRange("192.168.60.26-192.168.60.37");
     range.Begin.AddressFamily.Is(AddressFamily.InterNetwork);
     range.Begin.ToString().Is("192.168.60.26");
     range.End.AddressFamily.Is(AddressFamily.InterNetwork);
     range.End.ToString().Is("192.168.60.37");
 }
Exemplo n.º 9
0
    public void ContainsTest_IPv4()
    {
        var range = new IPAddressRange("192.168.60.26-192.168.60.37");

        range.Contains(IPAddress.Parse("192.168.60.25")).Is(false);
        range.Contains(IPAddress.Parse("192.168.60.26")).Is(true);
        range.Contains(IPAddress.Parse("192.168.60.27")).Is(true);

        range.Contains(IPAddress.Parse("192.168.60.36")).Is(true);
        range.Contains(IPAddress.Parse("192.168.60.37")).Is(true);
        range.Contains(IPAddress.Parse("192.168.60.38")).Is(false);
    }
Exemplo n.º 10
0
        /// <summary>
        /// A constructor that parses the provided response information.
        /// </summary>
        /// <param name="responsedServers">The servers that responded to the request.</param>
        /// <param name="rawWhoisResponse">The raw response from the last server.</param>
        public WhoisResponse(string[] responsedServers, string rawWhoisResponse)
        {
            this.RespondedServers = responsedServers;
            this.Raw = rawWhoisResponse;

            // resolve Organization Name.
            var m1 = Regex.Match(this.Raw,
                @"(^f\.\W*\[組織名\]\W+(?<orgName>[^\r\n]+))|" +
                @"(^\s*(OrgName|descr|Registrant Organization|owner):\W+(?<orgName>[^\r\n]+))",
                RegexOptions.Multiline);
            if (m1.Success)
            {
                this.OrganizationName = m1.Groups["orgName"].Value;
            }

            // resolve Address Range.
            var m2 = Regex.Match(this.Raw, 
                @"(^a.\W*\[IPネットワークアドレス\]\W+(?<adr>[^\r\n]+))|"+
                @"(^(NetRange|CIDR|inetnum):\W+(?<adr>[^\r\n]+))",
                RegexOptions.Multiline);
            if (m2.Success)
            {
                this.AddressRange = IPAddressRange.Parse(m2.Groups["adr"].Value);
            }

            // resolve ARIN Address Range.
            if (responsedServers != null && responsedServers.Last() == "whois.arin.net")
            {
                var m3 = Regex.Matches(this.Raw,
                    @"(?<org>^.*) (?<adr>\d+\.\d+\.\d+\.\d+ - \d+\.\d+\.\d+\.\d+)",
                    RegexOptions.Multiline);
                if (m3.Count > 0)
                {
                    var mymatch = m3[m3.Count - 1];
                    // Test to see if the information was already picked up from above
                    if (mymatch.Groups["org"].Value.Trim() != "NetRange:" &&
                        mymatch.Groups["org"].Value.Trim() != "CIDR:" &&
                        mymatch.Groups["org"].Value.Trim() != "inetnum:")
                    {
                        this.AddressRange = IPAddressRange.Parse(mymatch.Groups["adr"].Value);
                        this.OrganizationName = mymatch.Groups["org"].Value.Trim();
                    }
                }
            }

        }
Exemplo n.º 11
0
 private bool Equals(IPAddressRange other)
 {
     return(Begin.Equals(other.Begin) && End.Equals(other.End));
 }
Exemplo n.º 12
0
    public void ContainsTest_IPv6()
    {
        var range = new IPAddressRange("FE80::/10");

        range.Contains(IPAddress.Parse("::1")).Is(false);
        range.Contains(IPAddress.Parse("fe80::d503:4ee:3882:c586")).Is(true);
        range.Contains(IPAddress.Parse("fe80::d503:4ee:3882:c586%3")).Is(true);
    }
Exemplo n.º 13
0
    public void ContainsTest_with_IPV4andv6_is_False_ever()
    {
        var fullRangeIPv6 = new IPAddressRange("::-fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
        fullRangeIPv6.Contains(new IPAddressRange("192.168.0.0/24")).Is(false);

        var fullRangeIPv4 = new IPAddressRange("0.0.0.0-255.255.255.255");
        fullRangeIPv4.Contains(new IPAddressRange("::1-::2")).Is(false);
    }
Exemplo n.º 14
0
    public void ContainsTest_TestIPv6_to_IPv4Range()
    {
        var range = new IPAddressRange("192.168.60.26-192.168.60.37");

        range.Contains(IPAddress.Parse("c0a8:3c1a::")).Is(false);
    }
Exemplo n.º 15
0
    public void ContainsTest_Range_is_True_IPv4()
    {
        var range = new IPAddressRange("192.168.60.26-192.168.60.37");
        var range1_same = new IPAddressRange("192.168.60.26-192.168.60.37");
        var range2_samestart = new IPAddressRange("192.168.60.26-192.168.60.30");
        var range3_sameend = new IPAddressRange("192.168.60.36-192.168.60.37");
        var range4_subset = new IPAddressRange("192.168.60.29-192.168.60.32");

        range.Contains(range1_same).Is(true);
        range.Contains(range2_samestart).Is(true);
        range.Contains(range3_sameend).Is(true);
        range.Contains(range4_subset).Is(true);
    }
Exemplo n.º 16
0
    public void ContainsTest_Range_is_False_IPv4()
    {
        var range = new IPAddressRange("192.168.60.29-192.168.60.32");
        var range1_overLeft = new IPAddressRange("192.168.60.26-192.168.70.1");
        var range2_overRight = new IPAddressRange("192.168.50.1-192.168.60.37");
        var range3_outOfLeft = new IPAddressRange("192.168.50.30-192.168.50.31");
        var range4_outOfRight = new IPAddressRange("192.168.70.30-192.168.70.31");

        range.Contains(range1_overLeft).Is(false);
        range.Contains(range2_overRight).Is(false);
        range.Contains(range3_outOfLeft).Is(false);
        range.Contains(range4_outOfRight).Is(false);
    }
Exemplo n.º 17
0
 public void ParseTest_IPv6_CIDR()
 {
     var range = new IPAddressRange("fe80::/10");
     range.Begin.AddressFamily.Is(AddressFamily.InterNetworkV6);
     range.Begin.ToString().Is("fe80::");
     range.End.AddressFamily.Is(AddressFamily.InterNetworkV6);
     range.End.ToString().Is("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
 }
Exemplo n.º 18
0
    public void ContainsTest_Range_is_False_IPv6()
    {
        var range = new IPAddressRange("fe80::d503:4ee:3882:c586-fe80::d504:4ee:3882:c586");
        var range1_overLeft = new IPAddressRange("fe80::d502:4ee:3882:c586-fe80::d503:4ee:3882:c586");
        var range2_overRight = new IPAddressRange("fe80::d503:4ef:3882:c586-fe80::d505:4ee:3882:c586");
        var range3_outOfLeft = new IPAddressRange("fe80::d501:4ee:3882:c586-fe80::d502:4ee:3882:c586");
        var range4_outOfRight = new IPAddressRange("fe80::d505:4ee:3882:c586-fe80::d506:4ee:3882:c586");

        range.Contains(range1_overLeft).Is(false);
        range.Contains(range2_overRight).Is(false);
        range.Contains(range3_outOfLeft).Is(false);
        range.Contains(range4_outOfRight).Is(false);
    }
Exemplo n.º 19
0
 public void SubnetMaskLengthTest_Valid()
 {
     var range = new IPAddressRange(IPAddress.Parse("192.168.75.23"), IPAddressRange.SubnetMaskLength(IPAddress.Parse("255.255.254.0")));
     range.Begin.ToString().Is("192.168.74.0");
     range.End.ToString().Is("192.168.75.255");
 }
Exemplo n.º 20
0
    public void ContainsTest_Range_is_True_IPv6()
    {
        var range = new IPAddressRange("fe80::/10");
        var range1_same = new IPAddressRange("fe80::/10");
        var range2_samestart = new IPAddressRange("fe80::-fe80::d503:4ee:3882:c586");
        var range3_sameend = new IPAddressRange("fe80::d503:4ee:3882:c586-febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
        var range4_subset = new IPAddressRange("fe80::d503:4ee:3882:c586-fe80::d504:4ee:3882:c586");

        range.Contains(range1_same).Is(true);
        range.Contains(range2_samestart).Is(true);
        range.Contains(range3_sameend).Is(true);
        range.Contains(range4_subset).Is(true);
    }
 public bool Equals(IPAddressRange other)
 {
     return(other != null && Begin.Equals(other.Begin) && End.Equals(other.End));
 }