/// <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); }
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); }
/// <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); }
/// <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)); }