Exemple #1
0
        /// <summary>
        /// Queries asn.cymru.com for a TXT record
        /// {Reverse-IPaddress}.origin.asn.cymru.com
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        //internal string GetASN(string ipAddress)
        //{
        //    string asnResult = string.Empty;
        //    try
        //    {
        //        Response resp = _resolver.Query(string.Join(".", ipAddress.Split('.').Reverse()) + ".origin.asn.cymru.com", QType.TXT, QClass.IN);

        //        if (resp.Answers.Count > 0)
        //        {
        //            RecordTXT txtRecord = resp.Answers[0].RECORD as RecordTXT;
        //            if (!Object.Equals(txtRecord, null))
        //                asnResult = txtRecord.ASN;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        ExceptionExtensions.LogError(e, "Dig.GetASN", "IPAddress: " + ipAddress);
        //    }


        //    return asnResult;
        //}
        internal string GetASN(string ipAddress)
        {
            string asnResult = string.Empty;

            try
            {
                DnsQuery _dnsQuery = new DnsQuery(_dnsServers, string.Join(".", ipAddress.Split('.').Reverse()) + ".origin.asn.cymru.com");
                if (Object.Equals(null, _dnsQuery))
                {
                    ExceptionExtensions.LogError(new ArgumentNullException("dnsQuery is NULL"), "Dig.GetASN", "dns servers count: " + _dnsServers.Count);
                    return(null);
                }

                DnsAnswer resp = _dnsQuery.QueryServers(RecordType.TXT);

                if (!Object.Equals(null, resp) && resp.Answers.Count > 0)
                {
                    TxtRecord txtRecord = resp.Answers[0].Data as TxtRecord;
                    if (!Object.Equals(txtRecord, null))
                    {
                        asnResult = txtRecord.ASN;
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "Dig.GetASN", "IPAddress: " + ipAddress);
            }


            return(asnResult);
        }
Exemple #2
0
        internal ARecord GetARecord(string domainName)
        {
            try
            {
                DnsQuery _dnsQuery = new DnsQuery(_dnsServers, domainName);

                if (Object.Equals(null, _dnsQuery))
                {
                    ExceptionExtensions.LogError(new ArgumentNullException("dnsQuery is NULL"), "Dig.GetARecord", "dns servers count: " + _dnsServers.Count);
                    return(null);
                }

                DnsAnswer answer = _dnsQuery.QueryServers(RecordType.A);

                if (!Object.Equals(answer, null) && answer.Answers.Count > 0)
                {
                    foreach (Answer item in answer.Answers)
                    {
                        if (!Object.Equals(null, item) && item.RecType == RecordType.A && !Object.Equals(null, item.Data))
                        {
                            return(item.Data as ARecord);
                        }
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "Dig.GetARecord", "Domain: " + domainName);
            }

            return(null);
        }
Exemple #3
0
        private void btnLookUp_Click(object sender, EventArgs e)
        {
            //Lookup Resource Record,
            //Enter App in Wait State
            //Print Result, Exit

            if (txtHost.Text == null || txtHost.Text.Length == 0)
            {
                MessageBox.Show("Enter valid Host!");
                txtHost.Focus();
                return;
            }

            Application.DoEvents();
            sbrResult.Text = "Please wait...";
            this.Enabled   = false;
            Application.DoEvents();


            DnsQuery query = new DnsQuery();

            query.Domain    = txtHost.Text;
            query.DnsServer = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(txtDNS.Text.Trim()), 53);
            try
            {
                DnsAnswer answer = query.QueryServer(ParseEnumFromCombo());
                if (answer != null)
                {
                    DNS.frmDNSResult result = new ActiveUp.Net.Samples.Compact.DNS.frmDNSResult();
                    result.Output = answer;
                    result.ShowDialog();
                    result.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            sbrResult.Text = "Ready";
            this.Enabled   = true;
            EnableControls();
            Application.DoEvents();
        }
Exemple #4
0
        /// <summary>
        /// Get the MX records for the specified domain name using the specified DNS server.
        /// </summary>
        /// <param name="address">The domain name.</param>
        /// <param name="host">The host name of the DNS server to use.</param>
        /// <param name="port">The port number of the DNS server to use.</param>
        /// <param name="timeout">The timeout in miliseconds.</param>
        /// <returns>A collection of Mx Records.</returns>
        public static MxRecordCollection GetMxRecords(string address, string host, int port, int timeout)
        {
            var mxRecords = new MxRecordCollection();
            var query     = new DnsQuery(IPAddress.Parse(host))
            {
                RecursiveQuery = true,
                DnsServer      = { Port = port },
                Domain         = address
            };
            DnsAnswer answer = query.QueryServer(RecordType.MX, timeout);

            foreach (Answer entry in answer.Answers)
            {
                var mxRecord = (MXRecord)entry.Data;
                mxRecords.Add(mxRecord.Domain, mxRecord.Preference);
            }

            return(mxRecords);
        }
Exemple #5
0
        /// <summary>
        /// Gets the RBL ip.
        /// </summary>
        /// <param name="rblServer">The RBL server.</param>
        /// <param name="ip">The ip.</param>
        /// <returns></returns>
        public IPAddress GetRblIp(string rblServer, IPAddress ip)
        {
            DnsQuery query = new DnsQuery("213.254.203.215");

            byte[] addressBytes = ip.GetAddressBytes();
            string domain       = string.Format("{0}.{1}.{2}.{3}.{4}", addressBytes[3].ToString(),
                                                addressBytes[2].ToString(), addressBytes[1].ToString(), addressBytes[0].ToString(), rblServer);

            query.Domain = domain;
            DnsAnswer answer = query.QueryServer(RecordType.A);

            if (answer == null || answer.Answers.Count == 0)
            {
                return(null);
            }

            string result = answer.Answers[0].Data.ToString().Replace("IP Address: ", "");

            return(IPAddress.Parse(result));
        }
Exemple #6
0
        /// <summary>
        /// Queries for NS records.  These records are used in the lookup table for DNS HOST
        /// </summary>
        /// <param name="domainName"></param>
        /// <returns>List of RecordDNS</returns>
        //internal List<RecordNS> GetNSRecords(string domainName)
        //{
        //    List<RecordNS> records = new List<RecordNS>();
        //    try
        //    {
        //        Response resp = _resolver.Query(domainName, QType.NS, QClass.IN);

        //        if (resp.Answers.Count > 0)
        //            records = resp.Answers.Select(rec => rec.RECORD as RecordNS).ToList();
        //    }
        //    catch (Exception e)
        //    {
        //        ExceptionExtensions.LogError(e, "Dig.GetNSRecords", "Domain: " + domainName);
        //    }

        //    return records;
        //}
        internal List <NSRecord> GetNSRecords(string domainName)
        {
            List <NSRecord> records = new List <NSRecord>();

            try
            {
                DnsQuery  _dnsQuery = new DnsQuery(_dnsServers, domainName);
                DnsAnswer resp      = _dnsQuery.QueryServers(RecordType.NS);

                if (!Object.Equals(null, resp) && resp.Answers.Count > 0)
                {
                    records = resp.Answers.Select(rec => rec.Data as NSRecord).ToList();
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "Dig.GetNSRecords", "Domain: " + domainName);
            }

            return(records);
        }
Exemple #7
0
        /// <summary>
        /// Get the MX records for the specified domain name using the specified DNS server.
        /// </summary>
        /// <param name="address">The domain name.</param>
        /// <param name="host">The host name of the DNS server to use.</param>
        /// <param name="port">The port number of the DNS server to use.</param>
        /// <param name="timeout">The timeout in miliseconds.</param>
        /// <returns>A collection of Mx Records.</returns>
        public static ActiveUp.Net.Mail.MxRecordCollection GetMxRecords(string address, string host, int port, int timeout)
        {
            MxRecordCollection mxRecords = new MxRecordCollection();

            DnsQuery query = new DnsQuery(IPAddress.Parse(host));

            query.RecursiveQuery = true;
            query.DnsServer.Port = port;
            query.Domain         = address;

            DnsAnswer answer = query.QueryServer(RecordType.MX, timeout);

            foreach (DnsEntry entry in answer.Answers)
            {
                MXRecord mxRecord = (MXRecord)entry.Data;

                mxRecords.Add(mxRecord.Domain, mxRecord.Preference);
            }

            return(mxRecords);
        }
Exemple #8
0
        /// <summary>
        /// Uses {IP}origin.asn.cymru.com to get ASN and then additional information
        /// from {AS#}asn.cymru.com to get company name
        /// </summary>
        /// <param name="p"></param>
        /// <returns>Company name from AS records</returns>
        public string GetWebHostName(string domainName)
        {
            string companyName = "None";
            string asn         = string.Empty;

            try
            {
                IPAddress ip = GetIPAddress(domainName);

                if (!Object.Equals(ip, null))
                {
                    asn = GetASN(ip.ToString());
                    if (asn.Contains(" "))
                    {
                        asn = asn.Split(' ')[0];
                    }

                    DnsQuery  _dnsQuery = new DnsQuery(_dnsServers, string.Format("AS{0}.asn.cymru.com", asn));
                    DnsAnswer resp      = _dnsQuery.QueryServers(RecordType.TXT);

                    if (!Object.Equals(resp, null) && resp.Answers.Count > 0 && !Object.Equals(resp.Answers[0], null))
                    {
                        TxtRecord txtRecord = resp.Answers[0].Data as TxtRecord;
                        if (!Object.Equals(txtRecord, null))
                        {
                            companyName = txtRecord.COMPANY;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "Dig.GetWebHostName", "Domain: " + domainName);
            }

            return(GetCompanyFromRecordName(companyName, domainName, DigTypeEnum.WEB));
        }
Exemple #9
0
 protected bool Equals(DnsAnswer other)
 {
     return(string.Equals(Name, other.Name) && AnswerType == other.AnswerType);
 }
 public DnsCacheEntry(DnsAnswer answer)
 {
     LowestRecordTimeToLive = answer.Answers.Min(x => x.TimeToLive);
     Data = DnsByteExtensions.ToBytes(answer);
 }