Esempio n. 1
0
        private static Dictionary <string, DomainValue> ParseMaps(JToken maps)
        {
            var toReturn = new Dictionary <string, DomainValue>();

            if (maps != null && maps.Type == JTokenType.Object)
            {
                foreach (JProperty map in maps.Where(m => m is JProperty))
                {
                    if (map.Value.Type == JTokenType.Object)
                    {
                        toReturn.Add(map.Name, new DomainValue(map.Value.ToString()));
                    }
                    else if (map.Value.Type == JTokenType.String)
                    {
                        DomainValue newMap = DomainValue.FromIP((string)map.Value);
                        if (newMap != null)
                        {
                            toReturn.Add(map.Name, newMap);
                        }
                    }
                    else if (map.Value.Type == JTokenType.Array)
                    {
                        var         ipStrings = ((JArray)map.Value).Where(m => m.Type == JTokenType.String).Select(m => m.Value <string>());
                        DomainValue newMap    = DomainValue.FromIP(ipStrings);
                        if (newMap != null)
                        {
                            toReturn.Add(map.Name, newMap);
                        }
                    }
                }
            }
            return(toReturn);
        }
        public void ReadIpLists()
        {
            var domain = new DomainValue(Example_2_5_generic);

            IPAddress ip4expected = IPAddress.Parse("192.168.1.1");
            IPAddress ip6expected = IPAddress.Parse("2001:4860:0:1001::68");

            Assert.AreEqual(ip4expected, domain.Ips.First());
            Assert.AreEqual(ip6expected, domain.Ip6s.First());
        }
        public void ReadDomain_V2_5()
        {
            var domain = new DomainValue(Example_2_5_generic);

            Assert.AreEqual("192.168.1.1", domain.Ips.Select(m=>m.ToString()).First());
            Assert.AreEqual("2001:4860:0:1001::68", domain.Ip6s.Select(m => m.ToString()).First());
            Assert.AreEqual("eqt5g4fuenphqinx.onion", domain.Tor);
            Assert.AreEqual("*****@*****.**", domain.Email);
            Assert.AreEqual("Example & Sons Co.", domain.Info.First());
        }
        public void ReadMapsOnly1()
        {
            var domain = new DomainValue(Example_mapsonly1);

            domain.ImportDefaultMap();

            IPAddress expected = new IPAddress(new byte[] { 1, 1, 1, 1 });

            Assert.AreEqual(expected, domain.Ips.Single());
        }
Esempio n. 5
0
 public void ImportValues(DomainValue from, bool overwrite = false)
 {
     foreach (JProperty item in from.domain.Properties())
     {
         if (overwrite || domain[item.Name] == null)
         {
             domain[item.Name] = item.Value;
             Invalidate(item.Name);
         }
     }
 }
Esempio n. 6
0
        private static DomainValue FromIP(string p)
        {
            IPAddress ip = TryGetIP(p);

            if (ip != null)
            {
                return(DomainValue.FromIP(ip));
            }
            else
            {
                return(null);
            }
        }
        public void ReadMapsOnly2()
        {
            var domain = new DomainValue(Example_mapsonly2);

            domain.ImportDefaultMap();

            IPAddress expectedIp1 = new IPAddress(new byte[] { 10, 2, 3, 4 });
            IPAddress expectedIp2 = new IPAddress(new byte[] { 10, 4, 3, 2 });

            int expectedNsCount = 2;

            Assert.AreEqual(expectedIp1, domain.Ips.First());
            Assert.AreEqual(expectedIp2, domain.Ips.Last());

            Assert.AreEqual(expectedNsCount, domain.Ns.Count());
        }
        public void ReadMaps()
        {
            var domain = new DomainValue(Example_2_5_generic);

            var www = domain.GetMap("www");
            var wwwAlias = www.Alias;
            Assert.AreEqual("", wwwAlias);

            var ftp = domain.GetMap("ftp");
            var ftpIp = ftp.Ips.Select(m => m.ToString());
            Assert.AreEqual("10.2.3.4", ftpIp.First());
            Assert.AreEqual("10.4.3.2", ftpIp.Skip(1).First());

            var mail = domain.GetMap("mail");
            var mailNs = mail.Ns;
            Assert.AreEqual("ns1.host.net", mailNs.First());
            Assert.AreEqual("ns12.host.net", mailNs.Skip(1).First());

            var none = domain.GetMap("none");
            Assert.IsNull(none);
        }
        internal static DomainValue ResolveSubdomain(string[] domainparts, DomainValue value)
        {
            if (domainparts.Length > 2) // sub-domain
            {
                for (int i = domainparts.Length - 3; i >= 0; i--)
                {
                    if (string.IsNullOrWhiteSpace(domainparts[i]))
                    {
                        value = null;
                        break;
                    }

                    var sub = value.GetMap(domainparts[i]);
                    if (sub == null)
                        sub = value.GetMap("*");
                    if (sub == null)
                        break;
                    value = sub;
                }

            }
            return value;
        }
        public void ReadTLSRecord()
        {
            var domain = new DomainValue(Example_2_5_generic);

            var p443 = domain.GetTlsForPort("tcp", "443");
            var p443first = p443.First;
            Assert.AreEqual(1, (int)p443first[0]);
            Assert.AreEqual("660008F91C07DCF9058CDD5AD2BAF6CC9EAE0F912B8B54744CB7643D7621B787", (string)p443first[1]);
            Assert.AreEqual(1, (int)p443first[2]);

            var p25 = domain.GetTlsForPort("tcp", "25");
            var p25first = p25.First;
            Assert.AreEqual(1, (int)p25first[0]);
            Assert.AreEqual("660008F91C07DCF9058CDD5AD2BAF6CC9EAE0F912B8B54744CB7643D7621B787", (string)p25first[1]);
            Assert.AreEqual(1, (int)p25first[2]);

            var p123 = domain.GetTlsForPort("tcp", "123");
            Assert.IsNull(p123);

            var p321 = domain.GetTlsForPort("bull", "321");
            Assert.IsNull(p321);
        }
        public void ReadServiceRecord()
        {
            var domain = new DomainValue(Example_2_5_generic);

            ServiceRecord servicerecord = domain.Service.First();
            Assert.AreEqual("smtp", servicerecord.SrvName);
            Assert.AreEqual("tcp", servicerecord.Protocol);
            Assert.AreEqual(10, servicerecord.Priority);
            Assert.AreEqual(0, servicerecord.Weight);
            Assert.AreEqual(25, servicerecord.Port);
            Assert.AreEqual("mail", servicerecord.Target);
        }
 public void ReadNameServerList()
 {
     var domain = new DomainValue(Example_nameservers);
     var nameservers = domain.Ns;
     Assert.AreEqual("192.168.1.1", nameservers.First());
     Assert.AreEqual("10.2.3.4", nameservers.Last());
 }