/// <summary> /// Acts as a Factory which reads QType from Immutable IResource param to return concrete type which implements IResource. /// </summary> /// <param name="data"></param> /// <param name="position"></param> /// <param name="resource"></param> /// <returns></returns> private static IResource ReadAnswer(ref byte[] data, int position, IResource resource) { switch (resource.Type) { case QType.TXT: return(TxtRecord.Parse(data, position, resource)); case QType.MX: return(MxRecord.Parse(data, position, resource)); case QType.A: return(ARecord.Parse(data, position, resource)); case QType.SOA: return(SoaRecord.Parse(data, position, resource)); case QType.NS: return(NsRecord.Parse(data, position, resource)); case QType.CNAME: return(CNameRecord.Parse(data, position, resource)); } return(null); //TODO: Thrown Exception Here }
private MxRecordTlsSecurityProfile CreateSecurityProfile(int failureCount = 0) { MxRecord mxRecord = new MxRecord(1, "host"); TlsTestResult tlsTestResult = new TlsTestResult(TlsVersion.TlsV12, CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, CurveGroup.Ffdhe2048, SignatureHashAlgorithm.SHA1_DSA, null, null, null); TlsSecurityProfile tlsSecurityProfile = new TlsSecurityProfile( 1, null, new TlsTestResults( failureCount, new TlsTestResultsWithoutCertificate(tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult, tlsTestResult), new List <X509Certificate2> { TestCertificates.Certificate1 } )); return(new MxRecordTlsSecurityProfile(mxRecord, tlsSecurityProfile)); }
public override int GetHashCode() { unchecked { return(((MxRecord?.GetHashCode() ?? 0) * 397) ^ (TlsSecurityProfile?.GetHashCode() ?? 0)); } }
private static MxRecord CreateMxRecord(DbDataReader reader) { MxRecord record = new MxRecord( reader.GetUInt64("mx_record_id"), reader.GetString("mx_record_hostname")); return(record); }
public async Task <List <DomainTlsSecurityProfile> > GetSecurityProfilesForUpdate() { Stopwatch stopwatch = Stopwatch.StartNew(); Dictionary <Domain, Dictionary <MxRecord, MxRecordTlsSecurityProfile> > values = new Dictionary <Domain, Dictionary <MxRecord, MxRecordTlsSecurityProfile> >(); string connectionString = await _connectionInfo.GetConnectionStringAsync(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { await connection.OpenAsync().ConfigureAwait(false); MySqlCommand command = new MySqlCommand(TlsSecurityProfileDaoResources.SelectSecurityProfilesToUpdate, connection); command.Parameters.AddWithValue("refreshIntervalSeconds", _mxSecurityTesterConfig.RefreshIntervalSeconds); command.Parameters.AddWithValue("failureRefreshIntervalSeconds", _mxSecurityTesterConfig.FailureRefreshIntervalSeconds); command.Parameters.AddWithValue("limit", _mxSecurityTesterConfig.DomainLimit); using (DbDataReader reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { Domain domain = CreateDomain(reader); Dictionary <MxRecord, MxRecordTlsSecurityProfile> domainValue; if (!values.TryGetValue(domain, out domainValue)) { domainValue = new Dictionary <MxRecord, MxRecordTlsSecurityProfile>(); values.Add(domain, domainValue); } MxRecord record = CreateMxRecord(reader); MxRecordTlsSecurityProfile profile; if (!domainValue.TryGetValue(record, out profile)) { profile = new MxRecordTlsSecurityProfile(record, CreateTlsSecurityProfile(reader)); domainValue.Add(record, profile); } X509Certificate2 certificate = CreateCertificate(reader); if (certificate != null) { profile.TlsSecurityProfile.TlsResults.Certificates.Add(certificate); } } } connection.Close(); } stopwatch.Stop(); _log.Debug($"Retrieving domains to refresh security profiles for took {stopwatch.Elapsed}"); return(values.Select(_ => new DomainTlsSecurityProfile(_.Key, _.Value.Values.ToList())).ToList()); }
} // End Sub Test2 // Get mail exchangers for a domain name public static void Test2() { DnsMessage dnsMessage = DnsClient.Default.Resolve(ARSoft.Tools.Net.DomainName.Parse("example.com"), RecordType.Mx); if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain))) { throw new System.Exception("DNS request failed"); } else { foreach (DnsRecordBase dnsRecord in dnsMessage.AnswerRecords) { MxRecord mxRecord = dnsRecord as MxRecord; if (mxRecord != null) { System.Console.WriteLine(mxRecord.ExchangeDomainName); } } } } // End Sub Test2
public static bool TryParseReponse(string domain, string dnsServerAddress, byte[] rawResponse, out MxRecord[] records) { records = null; if (rawResponse.Length < WellKnownDnsResponsePositions.AnswersCountPosition) { return(false); } int status = rawResponse[WellKnownDnsResponsePositions.StatusPosition]; int answersCount = rawResponse[WellKnownDnsResponsePositions.AnswersCountPosition]; if (!CheckIfResponseIsValid(status, answersCount)) { Console.WriteLine("Response is corrupted or empty."); return(false); } records = new MxRecord[answersCount]; // lets skip the question and response general headers int position = domain.Length + WellKnownDnsResponsePositions.AnswerHeadersCount; for (int recordsIdx = 0; recordsIdx < answersCount; recordsIdx++) { MxRecord record = new MxRecord() { DnsServerAddress = dnsServerAddress, Domain = domain, Preference = rawResponse[position + WellKnownDnsResponsePositions.AnswerPreferencePosition] }; position += WellKnownDnsResponsePositions.AnswerPreferencePosition + 1; record.MailExchanger = GetMXRecord(position, rawResponse, out position); records[recordsIdx] = record; } return(true); }
private void _read() { _name = new DomainName(m_io, this, m_root); _type = ((DnsPacket.RecordType)m_io.ReadU2be()); _answerClass = ((DnsPacket.ClassType)m_io.ReadU2be()); _ttl = m_io.ReadS4be(); _rdlength = m_io.ReadU2be(); switch (Type) { case DnsPacket.RecordType.Aaaa: { _rdata = new AaaaRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.A: { _rdata = new ARecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Mx: { _rdata = new MxRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Cname: { _rdata = new CnameRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Ns: { _rdata = new NsRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Ptr: { _rdata = new PtrRecord(m_io, this, m_root); break; } } }
private List <MxRecord> GetAllRecordEntities() { List <MxRecord> records = new List <MxRecord>(); using (DbDataReader reader = MySqlHelper.ExecuteReader(ConnectionString, "SELECT * FROM dns_record_mx")) { while (reader.Read()) { MxRecord recordEntity = new MxRecord( reader.GetInt32("id"), reader.GetInt32("domain_id"), reader.GetInt32("preference"), reader.GetString("hostname"), reader.GetDateTime("start_date"), reader.GetDateTimeNullable("end_date"), reader.GetDateTime("last_checked"), reader.GetInt16("failure_count"), reader.GetInt16("result_code")); records.Add(recordEntity); } } return(records); }
public void TestConvertInterface() { var response = new byte[] { 41, 163, 133, 0, 0, 1, 0, 3, 0, 7, 0, 7, 5, 121, 97, 104, 111, 111, 3, 99, 111, 109, 0, 0, 15, 0, 1, 192, 12, 0, 15, 0, 1, 0, 0, 7, 8, 0, 25, 0, 1, 4, 109, 116, 97, 55, 3, 97, 109, 48, 8, 121, 97, 104, 111, 111, 100, 110, 115, 3, 110, 101, 116, 0, 192, 12, 0, 15, 0, 1, 0, 0, 7, 8, 0, 9, 0, 1, 4, 109, 116, 97, 54, 192, 46, 192, 12, 0, 15, 0, 1, 0, 0, 7, 8, 0, 9, 0, 1, 4, 109, 116, 97, 53, 192, 46, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 50, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 51, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 52, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 49, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 54, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 53, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 56, 192, 12, 192, 172, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 68, 180, 131, 16, 192, 118, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 68, 142, 255, 16, 192, 136, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 203, 84, 221, 53, 192, 154, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 98, 138, 11, 157, 192, 208, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 119, 160, 247, 124, 192, 190, 0, 1, 0, 1, 0, 2, 163, 0, 0, 4, 202, 43, 223, 170, 192, 226, 0, 1, 0, 1, 0, 2, 163, 0, 0, 4, 202, 165, 104, 22 }; IByteReader reader = new ByteReader(response); new DNS.MessageingConcretes.Question(reader); //Just to advance the position var expectedRr = new ResourceRecord(null) { Class = RecordClass.In, Name = "yahoo.com.", Rdata = new byte[] { 0, 1, 4, 109, 116, 97, 55, 3, 97, 109, 48, 8, 121, 97, 104, 111, 111, 100, 110, 115, 3, 110, 101, 116, 0 }, RdLength = 25, Ttl = 1800, Type = RecordType.MxRecord, Record = new DNS.RDataConcretes.MxRecord(null) { Preference = 1, Exchanger = "mta7.am0.yahoodns.net.", }, }; var actualRr = new ResourceRecord(reader); AssertEquality(expectedRr, actualRr); var expectedMx = new MxRecord { Class = RecordClass.In, Name = "yahoo.com.", Ttl = 1800, Type = RecordType.MxRecord, Preference = 1, Exchanger = "mta7.am0.yahoodns.net." }; var actualMx = actualRr.ConvertToExternalType() as MxRecord; AssertEquality(expectedMx, actualMx); }
public MxRecordTlsSecurityProfile(MxRecord mxRecord, TlsSecurityProfile tlsSecurityProfile) { MxRecord = mxRecord; TlsSecurityProfile = tlsSecurityProfile; }
protected void DeleteRecordEntry(object param) { List <object> objList = param as List <object>; RecordSet rs = objList?[0] as RecordSet; switch (GetRecordType(rs?.Type)) { case RecordType.A: { ARecord record = objList?[1] as ARecord; if (record != null) { rs.Properties.ARecords.Remove(record); } } break; case RecordType.AAAA: { AaaaRecord record = objList?[1] as AaaaRecord; if (record != null) { rs.Properties.AaaaRecords.Remove(record); } } break; case RecordType.MX: { MxRecord record = objList?[1] as MxRecord; if (record != null) { rs.Properties.MxRecords.Remove(record); } } break; case RecordType.SRV: { SrvRecord record = objList?[1] as SrvRecord; if (record != null) { rs.Properties.SrvRecords.Remove(record); } } break; case RecordType.TXT: { TxtRecord record = objList?[1] as TxtRecord; if (record != null) { rs.Properties.TxtRecords.Remove(record); } } break; } var r = new List <RecordSet>(Records); Records.Clear(); Records = new System.Collections.ObjectModel.ObservableCollection <RecordSet>(r); }
internal static RecordSetData DeserializeRecordSetData(JsonElement element) { Optional <string> etag = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <IDictionary <string, string> > metadata = default; Optional <long> ttl = default; Optional <string> fqdn = default; Optional <string> provisioningState = default; Optional <WritableSubResource> targetResource = default; Optional <IList <ARecord> > aRecords = default; Optional <IList <AaaaRecord> > aaaaRecords = default; Optional <IList <MxRecord> > mxRecords = default; Optional <IList <NsRecord> > nsRecords = default; Optional <IList <PtrRecord> > ptrRecords = default; Optional <IList <SrvRecord> > srvRecords = default; Optional <IList <TxtRecord> > txtRecords = default; Optional <CnameRecord> cnameRecord = default; Optional <SoaRecord> soaRecord = default; Optional <IList <CaaRecord> > caaRecords = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } metadata = dictionary; continue; } if (property0.NameEquals("TTL")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ttl = property0.Value.GetInt64(); continue; } if (property0.NameEquals("fqdn")) { fqdn = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("targetResource")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } targetResource = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("ARecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ARecord> array = new List <ARecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ARecord.DeserializeARecord(item)); } aRecords = array; continue; } if (property0.NameEquals("AAAARecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <AaaaRecord> array = new List <AaaaRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(AaaaRecord.DeserializeAaaaRecord(item)); } aaaaRecords = array; continue; } if (property0.NameEquals("MXRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <MxRecord> array = new List <MxRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(MxRecord.DeserializeMxRecord(item)); } mxRecords = array; continue; } if (property0.NameEquals("NSRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <NsRecord> array = new List <NsRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(NsRecord.DeserializeNsRecord(item)); } nsRecords = array; continue; } if (property0.NameEquals("PTRRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <PtrRecord> array = new List <PtrRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(PtrRecord.DeserializePtrRecord(item)); } ptrRecords = array; continue; } if (property0.NameEquals("SRVRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <SrvRecord> array = new List <SrvRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(SrvRecord.DeserializeSrvRecord(item)); } srvRecords = array; continue; } if (property0.NameEquals("TXTRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <TxtRecord> array = new List <TxtRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(TxtRecord.DeserializeTxtRecord(item)); } txtRecords = array; continue; } if (property0.NameEquals("CNAMERecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cnameRecord = CnameRecord.DeserializeCnameRecord(property0.Value); continue; } if (property0.NameEquals("SOARecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } soaRecord = SoaRecord.DeserializeSoaRecord(property0.Value); continue; } if (property0.NameEquals("caaRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <CaaRecord> array = new List <CaaRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(CaaRecord.DeserializeCaaRecord(item)); } caaRecords = array; continue; } } continue; } } return(new RecordSetData(id, name, type, systemData, etag.Value, Optional.ToDictionary(metadata), Optional.ToNullable(ttl), fqdn.Value, provisioningState.Value, targetResource, Optional.ToList(aRecords), Optional.ToList(aaaaRecords), Optional.ToList(mxRecords), Optional.ToList(nsRecords), Optional.ToList(ptrRecords), Optional.ToList(srvRecords), Optional.ToList(txtRecords), cnameRecord.Value, soaRecord.Value, Optional.ToList(caaRecords))); }
protected void MXRecordCheck(DnsResourceRecord record, MxRecord mxrecord) { bool online = false; bool acc25 = false; bool acc465 = false; bool acc587 = false; bool allowsRelay = false; if (InvokeRequired) { WriteLineInvoke("Found MX record " + record.ToString(), Color.Gainsboro); if (mxrecord == null || mxrecord.Exchange == null) { Invoke(new Finished(WriteEmptyLine)); return; } UpdateStatusInvoke("Attempting to ping host " + mxrecord.Exchange); if (CanPingHost(mxrecord.Exchange)) { online = true; UpdateStatusInvoke("Attempting to acess host on port 25..."); if (CanReachHost(mxrecord.Exchange, 25)) { acc25 = true; } UpdateStatusInvoke("Attempting to acess host on port 465..."); if (CanReachHost(mxrecord.Exchange, 465)) { acc465 = true; } UpdateStatusInvoke("Attempting to acess host on port 587..."); if (CanReachHost(mxrecord.Exchange, 587)) { acc587 = true; } if (acc25) { UpdateStatusInvoke("Attempting to communicate using SMTP on port 25..."); EmailServerStatus ess = CheckEmailServer(mxrecord.Exchange, 25); if (ess.AllowsRelay) { allowsRelay = true; } } } if (!online) { WriteLineInvoke("Host appears offline!", Color.OrangeRed); } else { WriteStringInvoke("Host online! ", Color.YellowGreen); WriteStringInvoke("25 ", Color.Gainsboro); if (acc25) { WriteStringInvoke("Open ", Color.YellowGreen); } else { WriteStringInvoke("Closed ", Color.OrangeRed); } WriteStringInvoke("465 ", Color.Gainsboro); if (acc465) { WriteStringInvoke("Open ", Color.YellowGreen); } else { WriteStringInvoke("Closed ", Color.OrangeRed); } WriteStringInvoke("587 ", Color.Gainsboro); if (acc587) { WriteLineInvoke("Open", Color.YellowGreen); } else { WriteLineInvoke("Closed", Color.OrangeRed); } if (allowsRelay) { WriteLineInvoke("Warning: Host allows relaying!", Color.OrangeRed); } } Invoke(new Finished(WriteEmptyLine)); } }
private static DnsMxRecord TranformMxRecord(MxRecord lookupMx) { return(new DnsMxRecord(lookupMx.Exchange, lookupMx.Preference)); }
private static (List <dynamic> list, int statusCode) ResolveOverHttps(string clientIpAddress, string domainName, bool proxyEnable = false, IWebProxy wProxy = null, RecordType type = RecordType.A) { string dnsStr; List <dynamic> recordList = new List <dynamic>(); using (WebClient webClient = new WebClient()) { webClient.Headers["User-Agent"] = "AuroraDNSC/0.1"; if (proxyEnable) { webClient.Proxy = wProxy; } dnsStr = webClient.DownloadString( ADnsSetting.HttpsDnsUrl + @"?ct=application/dns-json&" + $"name={domainName}&type={type.ToString().ToUpper()}&edns_client_subnet={clientIpAddress}"); } JsonValue dnsJsonValue = Json.Parse(dnsStr); int statusCode = dnsJsonValue.AsObjectGetInt("Status"); if (statusCode != 0) { return(new List <dynamic>(), statusCode); } if (dnsStr.Contains("\"Answer\"")) { var dnsAnswerJsonList = dnsJsonValue.AsObjectGetArray("Answer"); foreach (var itemJsonValue in dnsAnswerJsonList) { string answerAddr = itemJsonValue.AsObjectGetString("data"); string answerDomainName = itemJsonValue.AsObjectGetString("name"); int answerType = itemJsonValue.AsObjectGetInt("type"); int ttl = itemJsonValue.AsObjectGetInt("TTL"); if (type == RecordType.A) { if (Convert.ToInt32(RecordType.A) == answerType) { ARecord aRecord = new ARecord( DomainName.Parse(answerDomainName), ttl, IPAddress.Parse(answerAddr)); recordList.Add(aRecord); } else if (Convert.ToInt32(RecordType.CName) == answerType) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); //recordList.AddRange(ResolveOverHttps(clientIpAddress,answerAddr)); //return recordList; } } else if (type == RecordType.Aaaa && ADnsSetting.IPv6Enable) { if (Convert.ToInt32(RecordType.Aaaa) == answerType) { AaaaRecord aaaaRecord = new AaaaRecord( DomainName.Parse(answerDomainName), ttl, IPAddress.Parse(answerAddr)); recordList.Add(aaaaRecord); } else if (Convert.ToInt32(RecordType.CName) == answerType) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); } } else if (type == RecordType.CName && answerType == Convert.ToInt32(RecordType.CName)) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); } else if (type == RecordType.Ns && answerType == Convert.ToInt32(RecordType.Ns)) { NsRecord nsRecord = new NsRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(nsRecord); } else if (type == RecordType.Mx && answerType == Convert.ToInt32(RecordType.Mx)) { MxRecord mxRecord = new MxRecord( DomainName.Parse(answerDomainName), ttl, ushort.Parse(answerAddr.Split(' ')[0]), DomainName.Parse(answerAddr.Split(' ')[1])); recordList.Add(mxRecord); } else if (type == RecordType.Txt && answerType == Convert.ToInt32(RecordType.Txt)) { TxtRecord txtRecord = new TxtRecord(DomainName.Parse(answerDomainName), ttl, answerAddr); recordList.Add(txtRecord); } else if (type == RecordType.Ptr && answerType == Convert.ToInt32(RecordType.Ptr)) { PtrRecord ptrRecord = new PtrRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(ptrRecord); } } } return(recordList, statusCode); }
internal virtual void AssertEquality(MxRecord expected, MxRecord actual) { Assert.AreEqual(expected.Preference, actual.Preference, "Should be equal"); Assert.AreEqual(expected.Exchanger, actual.Exchanger, "Should be equal"); }
internal SpfQualifier CheckHost(SpfCheckHostParameter parameters) { DnsMessage dnsMessage; SpfMechanism spfMechanism = this as SpfMechanism; if (spfMechanism != null) { switch (spfMechanism.Type) { case SpfMechanismType.All: return(spfMechanism.Qualifier); case SpfMechanismType.A: bool?isAMatch = IsIpMatch(String.IsNullOrEmpty(spfMechanism.Domain) ? parameters.CurrentDomain : spfMechanism.Domain, parameters.ClientAddress, spfMechanism.Prefix, spfMechanism.Prefix6); if (!isAMatch.HasValue) { return(SpfQualifier.TempError); } if (isAMatch.Value) { return(spfMechanism.Qualifier); } break; case SpfMechanismType.Mx: dnsMessage = DnsClient.Default.Resolve(ExpandDomain(String.IsNullOrEmpty(spfMechanism.Domain) ? parameters.CurrentDomain : spfMechanism.Domain, parameters), RecordType.Mx); if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain))) { return(SpfQualifier.TempError); } int mxCheckedCount = 0; foreach (DnsRecordBase dnsRecord in dnsMessage.AnswerRecords) { MxRecord mxRecord = dnsRecord as MxRecord; if (mxRecord != null) { if (++mxCheckedCount == 10) { break; } bool?isMxMatch = IsIpMatch(mxRecord.ExchangeDomainName, parameters.ClientAddress, spfMechanism.Prefix, spfMechanism.Prefix6); if (!isMxMatch.HasValue) { return(SpfQualifier.TempError); } if (isMxMatch.Value) { return(spfMechanism.Qualifier); } } } break; case SpfMechanismType.Ip4: case SpfMechanismType.Ip6: IPAddress compareAddress; if (IPAddress.TryParse(spfMechanism.Domain, out compareAddress)) { if (spfMechanism.Prefix.HasValue) { if (parameters.ClientAddress.GetNetworkAddress(spfMechanism.Prefix.Value).Equals(compareAddress.GetNetworkAddress(spfMechanism.Prefix.Value))) { return(spfMechanism.Qualifier); } } else if (parameters.ClientAddress.Equals(compareAddress)) { return(spfMechanism.Qualifier); } } else { return(SpfQualifier.PermError); } break; case SpfMechanismType.Ptr: dnsMessage = DnsClient.Default.Resolve(parameters.ClientAddress.GetReverseLookupAddress(), RecordType.Ptr); if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain))) { return(SpfQualifier.TempError); } string ptrCompareName = String.IsNullOrEmpty(spfMechanism.Domain) ? parameters.CurrentDomain : spfMechanism.Domain; int ptrCheckedCount = 0; if ((from ptrRecord in dnsMessage.AnswerRecords.OfType <PtrRecord>().TakeWhile(ptrRecord => ++ ptrCheckedCount != 10) let isPtrMatch = IsIpMatch(ptrRecord.PointerDomainName, parameters.ClientAddress, 0, 0) where isPtrMatch.HasValue && isPtrMatch.Value select ptrRecord).Any(ptrRecord => ptrRecord.PointerDomainName.Equals(ptrCompareName, StringComparison.InvariantCultureIgnoreCase) || (ptrRecord.PointerDomainName.EndsWith("." + ptrCompareName, StringComparison.InvariantCultureIgnoreCase)))) { return(spfMechanism.Qualifier); } break; case SpfMechanismType.Exist: if (String.IsNullOrEmpty(spfMechanism.Domain)) { return(SpfQualifier.PermError); } dnsMessage = DnsClient.Default.Resolve(ExpandDomain(spfMechanism.Domain, parameters), RecordType.A); if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain))) { return(SpfQualifier.TempError); } if (dnsMessage.AnswerRecords.Count(record => (record.RecordType == RecordType.A)) > 0) { return(spfMechanism.Qualifier); } break; case SpfMechanismType.Include: if (String.IsNullOrEmpty(spfMechanism.Domain)) { return(SpfQualifier.PermError); } string includeDomain = ExpandDomain(spfMechanism.Domain, parameters); switch (SpfRecord.CheckHost(includeDomain, new SpfCheckHostParameter(includeDomain, parameters))) { case SpfQualifier.Pass: return(spfMechanism.Qualifier); case SpfQualifier.Fail: case SpfQualifier.SoftFail: case SpfQualifier.Neutral: return(SpfQualifier.None); case SpfQualifier.TempError: return(SpfQualifier.TempError); case SpfQualifier.PermError: case SpfQualifier.None: return(SpfQualifier.PermError); } break; default: return(SpfQualifier.PermError); } } SpfModifier spfModifier = this as SpfModifier; if (spfModifier != null) { switch (spfModifier.Type) { case SpfModifierType.Redirect: if (String.IsNullOrEmpty(spfModifier.Domain)) { return(SpfQualifier.PermError); } string redirectDomain = ExpandDomain(spfModifier.Domain, parameters); return(SpfRecord.CheckHost(redirectDomain, new SpfCheckHostParameter(redirectDomain, parameters))); case SpfModifierType.Exp: break; default: return(SpfQualifier.PermError); } } return(SpfQualifier.None); }
/// <summary> /// Add a MxRecord object in the collection. /// </summary> /// <param name="mxRecord">The MxRecord object.</param> public void Add(MxRecord mxRecord) { List.Add(mxRecord); }
protected bool Equals(MxRecord other) { return(Id == other.Id && string.Equals(Hostname, other.Hostname)); }
private static (List <dynamic> list, ReturnCode statusCode) ResolveOverHttps(string clientIpAddress, string domainName, bool proxyEnable = false, IWebProxy wProxy = null, RecordType type = RecordType.A) { string dnsStr; List <dynamic> recordList = new List <dynamic>(); using (MWebClient webClient = new MWebClient()) { webClient.Headers["User-Agent"] = "AuroraDNSC/0.1"; // webClient.AllowAutoRedirect = false; if (proxyEnable) { webClient.Proxy = wProxy; } try { dnsStr = webClient.DownloadString( DnsSettings.HttpsDnsUrl + @"?ct=application/dns-json&" + $"name={domainName}&type={type.ToString().ToUpper()}&edns_client_subnet={clientIpAddress}"); } catch (WebException e) { HttpWebResponse response = (HttpWebResponse)e.Response; try { BgwLog($@"| - Catch WebException : {Convert.ToInt32(response.StatusCode)} {response.StatusCode} | {domainName}"); } catch (Exception exception) { BgwLog($@"| - Catch WebException : {exception.Message} | {domainName}"); //MainWindow.NotifyIcon.ShowBalloonTip(360, "AuroraDNS - 错误", // $"异常 : {exception.Message} {Environment.NewLine} {domainName}", ToolTipIcon.Warning); } return(new List <dynamic>(), ReturnCode.ServerFailure); } } JsonValue dnsJsonValue = Json.Parse(dnsStr); int statusCode = dnsJsonValue.AsObjectGetInt("Status"); if (statusCode != 0) { return(new List <dynamic>(), (ReturnCode)statusCode); } if (dnsStr.Contains("\"Answer\"")) { var dnsAnswerJsonList = dnsJsonValue.AsObjectGetArray("Answer"); foreach (var itemJsonValue in dnsAnswerJsonList) { string answerAddr = itemJsonValue.AsObjectGetString("data"); string answerDomainName = itemJsonValue.AsObjectGetString("name"); int answerType = itemJsonValue.AsObjectGetInt("type"); int ttl = itemJsonValue.AsObjectGetInt("TTL"); switch (type) { case RecordType.A: { if (Convert.ToInt32(RecordType.A) == answerType) { ARecord aRecord = new ARecord( DomainName.Parse(answerDomainName), ttl, IPAddress.Parse(answerAddr)); recordList.Add(aRecord); } else if (Convert.ToInt32(RecordType.CName) == answerType) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); //recordList.AddRange(ResolveOverHttps(clientIpAddress,answerAddr)); //return recordList; } break; } case RecordType.Aaaa: { if (Convert.ToInt32(RecordType.Aaaa) == answerType) { AaaaRecord aaaaRecord = new AaaaRecord( DomainName.Parse(answerDomainName), ttl, IPAddress.Parse(answerAddr)); recordList.Add(aaaaRecord); } else if (Convert.ToInt32(RecordType.CName) == answerType) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); } break; } case RecordType.CName when answerType == Convert.ToInt32(RecordType.CName): { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); break; } case RecordType.Ns when answerType == Convert.ToInt32(RecordType.Ns): { NsRecord nsRecord = new NsRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(nsRecord); break; } case RecordType.Mx when answerType == Convert.ToInt32(RecordType.Mx): { MxRecord mxRecord = new MxRecord( DomainName.Parse(answerDomainName), ttl, ushort.Parse(answerAddr.Split(' ')[0]), DomainName.Parse(answerAddr.Split(' ')[1])); recordList.Add(mxRecord); break; } case RecordType.Txt when answerType == Convert.ToInt32(RecordType.Txt): { TxtRecord txtRecord = new TxtRecord(DomainName.Parse(answerDomainName), ttl, answerAddr); recordList.Add(txtRecord); break; } case RecordType.Ptr when answerType == Convert.ToInt32(RecordType.Ptr): { PtrRecord ptrRecord = new PtrRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(ptrRecord); break; } default: { statusCode = Convert.ToInt32(ReturnCode.ServerFailure); break; } } } } return(recordList, (ReturnCode)statusCode); }
internal static MxRecordSetData DeserializeMxRecordSetData(JsonElement element) { Optional <string> etag = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <IDictionary <string, string> > metadata = default; Optional <long> ttl = default; Optional <string> fqdn = default; Optional <string> provisioningState = default; Optional <WritableSubResource> targetResource = default; Optional <IList <MxRecord> > mxRecords = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } metadata = dictionary; continue; } if (property0.NameEquals("TTL")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ttl = property0.Value.GetInt64(); continue; } if (property0.NameEquals("fqdn")) { fqdn = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("targetResource")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } targetResource = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("MXRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <MxRecord> array = new List <MxRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(MxRecord.DeserializeMxRecord(item)); } mxRecords = array; continue; } } continue; } } return(new MxRecordSetData(id, name, type, systemData, etag.Value, Optional.ToDictionary(metadata), Optional.ToNullable(ttl), fqdn.Value, provisioningState.Value, targetResource, Optional.ToList(mxRecords))); }
public static (List <DnsRecordBase> list, ReturnCode statusCode) ResolveOverHttpsByDnsJson(string clientIpAddress, string domainName, string dohUrl, bool proxyEnable = false, IWebProxy wProxy = null, RecordType type = RecordType.A) { string dnsStr; List <DnsRecordBase> recordList = new List <DnsRecordBase>(); try { dnsStr = MyCurl.GetString(dohUrl + @"?ct=application/dns-json&" + $"name={domainName}&type={type.ToString().ToUpper()}&edns_client_subnet={clientIpAddress}", DnsSettings.Http2Enable, proxyEnable, wProxy, DnsSettings.AllowAutoRedirect); } catch (WebException e) { HttpWebResponse response = (HttpWebResponse)e.Response; try { BackgroundLog($@"| - Catch WebException : {Convert.ToInt32(response.StatusCode)} {response.StatusCode} | {e.Status} | {domainName} | {response.ResponseUri}"); if (DnsSettings.HTTPStatusNotify) { MainWindow.NotifyIcon.ShowBalloonTip(360, "AuroraDNS - 错误", $"异常 :{Convert.ToInt32(response.StatusCode)} {response.StatusCode} {Environment.NewLine} {domainName}", ToolTipIcon.Warning); } if (response.StatusCode == HttpStatusCode.BadRequest) { DnsSettings.DnsMsgEnable = true; } } catch (Exception exception) { BackgroundLog($@"| - Catch WebException : {exception.Message} | {e.Status} | {domainName} | {dohUrl}" + @"?ct=application/dns-json&" + $"name={domainName}&type={type.ToString().ToUpper()}&edns_client_subnet={clientIpAddress}"); if (DnsSettings.HTTPStatusNotify) { MainWindow.NotifyIcon.ShowBalloonTip(360, "AuroraDNS - 错误", $"异常 : {exception.Message} {Environment.NewLine} {domainName}", ToolTipIcon.Warning); } } if (dohUrl != DnsSettings.HttpsDnsUrl) { return(new List <DnsRecordBase>(), ReturnCode.ServerFailure); } BackgroundLog($@"| -- SecondDoH : {DnsSettings.SecondHttpsDnsUrl}"); return(ResolveOverHttpsByDnsJson(clientIpAddress, domainName, DnsSettings.SecondHttpsDnsUrl, proxyEnable, wProxy, type)); } JsonValue dnsJsonValue = Json.Parse(dnsStr); int statusCode = dnsJsonValue.AsObjectGetInt("Status"); if (statusCode != 0) { return(new List <DnsRecordBase>(), (ReturnCode)statusCode); } if (dnsStr.Contains("\"Answer\"")) { var dnsAnswerJsonList = dnsJsonValue.AsObjectGetArray("Answer"); foreach (var itemJsonValue in dnsAnswerJsonList) { string answerAddr = itemJsonValue.AsObjectGetString("data"); string answerDomainName = itemJsonValue.AsObjectGetString("name"); int answerType = itemJsonValue.AsObjectGetInt("type"); int ttl = itemJsonValue.AsObjectGetInt("TTL"); switch (type) { case RecordType.A when Convert.ToInt32(RecordType.A) == answerType && !DnsSettings.Ipv4Disable: { ARecord aRecord = new ARecord( DomainName.Parse(answerDomainName), ttl, IPAddress.Parse(answerAddr)); recordList.Add(aRecord); break; } case RecordType.A: { if (Convert.ToInt32(RecordType.CName) == answerType) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); //recordList.AddRange(ResolveOverHttps(clientIpAddress,answerAddr)); //return recordList; } break; } case RecordType.Aaaa when Convert.ToInt32(RecordType.Aaaa) == answerType && !DnsSettings.Ipv6Disable: { AaaaRecord aaaaRecord = new AaaaRecord( DomainName.Parse(answerDomainName), ttl, IPAddress.Parse(answerAddr)); recordList.Add(aaaaRecord); break; } case RecordType.Aaaa: { if (Convert.ToInt32(RecordType.CName) == answerType) { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); } break; } case RecordType.CName when answerType == Convert.ToInt32(RecordType.CName): { CNameRecord cRecord = new CNameRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(cRecord); break; } case RecordType.Ns when answerType == Convert.ToInt32(RecordType.Ns): { NsRecord nsRecord = new NsRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(nsRecord); break; } case RecordType.Mx when answerType == Convert.ToInt32(RecordType.Mx): { MxRecord mxRecord = new MxRecord( DomainName.Parse(answerDomainName), ttl, ushort.Parse(answerAddr.Split(' ')[0]), DomainName.Parse(answerAddr.Split(' ')[1])); recordList.Add(mxRecord); break; } case RecordType.Txt when answerType == Convert.ToInt32(RecordType.Txt): { TxtRecord txtRecord = new TxtRecord(DomainName.Parse(answerDomainName), ttl, answerAddr); recordList.Add(txtRecord); break; } case RecordType.Ptr when answerType == Convert.ToInt32(RecordType.Ptr): { PtrRecord ptrRecord = new PtrRecord( DomainName.Parse(answerDomainName), ttl, DomainName.Parse(answerAddr)); recordList.Add(ptrRecord); break; } default: statusCode = Convert.ToInt32(ReturnCode.ServerFailure); break; } } } return(recordList, (ReturnCode)statusCode); }
static string ParseRecord(IDnsQueryResponse dnsQueryResponse, bool isA = false, bool isMx = false) { string output = ""; string value = ""; string ttl = ""; string mxp = ""; foreach (DnsResourceRecord record in dnsQueryResponse.Answers) { switch (record.RecordType) { case ResourceRecordType.MX: { MxRecord mxRecord = record as MxRecord; if (mxRecord != null) { value += mxRecord.Exchange + "\n"; ttl += mxRecord.InitialTimeToLive + "\n"; mxp += mxRecord.Preference + "\n"; // output += $"{mxRecord.Exchange} | TTL {mxRecord.InitialTimeToLive}\n"; } break; } case ResourceRecordType.SOA: { SoaRecord soaRecord = record as SoaRecord; if (soaRecord != null) { value += soaRecord.ToString() + "\n"; ttl += soaRecord.Minimum + "\n"; // output += $"SOA TTL {soaRecord.Minimum}\n"; } break; } case ResourceRecordType.NS: { NsRecord nsRecord = record as NsRecord; if (nsRecord != null) { value += nsRecord.NSDName + "\n"; ttl += nsRecord.InitialTimeToLive + "\n"; // output += $"{nsRecord.NSDName} | TTL {nsRecord.InitialTimeToLive}\n"; } break; } case ResourceRecordType.A: { ARecord nsRecord = record as ARecord; if (nsRecord != null) { return($"{nsRecord.InitialTimeToLive}"); } return("No record"); } case ResourceRecordType.TXT: { TxtRecord txtRecord = record as TxtRecord; if (txtRecord != null) { foreach (string txt in txtRecord.Text) { value += "\"\"" + txt + "\"\"\n"; ttl += txtRecord.InitialTimeToLive + "\n"; // output += $"\"{txt}\" | TTL {txtRecord.InitialTimeToLive}\n"; } } break; } } } if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(ttl)) { if (string.IsNullOrEmpty(mxp)) { output = $"\"{value.Trim()}\",\"{ttl.Trim()}\""; } else { output = $"\"{value.Trim()}\",\"{mxp.Trim()}\",\"{ttl.Trim()}\""; } } else { if (isA) { output = "No record"; } else if (isMx) { output = "No record,No record,No record"; } else { output = "No record,No record"; } } if (string.IsNullOrEmpty(output)) { return("No record\n"); } return(output); }
public override void ExecuteCmdlet() { DnsRecordBase result = null; switch (this.ParameterSetName) { case ParameterSetA: { result = new ARecord { Ipv4Address = this.Ipv4Address }; break; } case ParameterSetAaaa: { result = new AaaaRecord { Ipv6Address = this.Ipv6Address }; break; } case ParameterSetMx: { result = new MxRecord { Preference = this.Preference, Exchange = this.Exchange }; break; } case ParameterSetNs: { result = new NsRecord { Nsdname = this.Nsdname }; break; } case ParameterSetSrv: { result = new SrvRecord { Priority = this.Priority, Port = this.Port, Target = this.Target, Weight = this.Weight }; break; } case ParameterSetTxt: { result = new TxtRecord { Value = this.Value }; break; } case ParameterSetCName: { result = new CnameRecord { Cname = this.Cname }; break; } case ParameterSetPtr: { result = new PtrRecord {Ptrdname = this.Ptrdname}; break; } default: { throw new PSArgumentException(string.Format(ProjectResources.Error_UnknownParameterSetName, this.ParameterSetName)); } } WriteObject(result); }
private void button1_Click(object sender, EventArgs e) { if (runThread != null && runThread.IsAlive) { runThread.Abort(); button1.Text = "Check"; return; } string host = Hostname; bool checkA = CheckARecords; bool checkAAAA = CheckAAAARecords; bool checkMX = CheckMXRecords; bool checkTXT = CheckTXTRecords; bool checkSRV = CheckSRVRecords; bool checkPTR = CheckPTRRecords; bool validateSPF = ValidateSPFRecords; runThread = new Thread(new ThreadStart(delegate() { LookupClient lookupClient = new LookupClient(); if (InvokeRequired) { Invoke(new WriteString(WriteStringColor), new object[] { "Checking host ", richTextBox1.ForeColor }); Invoke(new WriteString(WriteLineColor), new object[] { host, Color.YellowGreen }); Invoke(new Finished(WriteEmptyLine)); } if (checkA) { var response = lookupClient.Query(host, QueryType.A); if (response.HasError) { if (InvokeRequired) { WriteLineInvoke("Failed to retrieve A records for host", Color.OrangeRed); Invoke(new Finished(WriteEmptyLine)); } } else { for (int i = 0; i < response.AllRecords.Count(); i++) { DnsResourceRecord record = response.AllRecords.ElementAt(i); ARecord arecord = null; if (response.Answers.Count > i) { arecord = response.Answers.OfType <ARecord>().ElementAt(i); } ARecordCheck(record, arecord); } } } if (checkMX) { var response = lookupClient.Query(host, QueryType.MX); if (response.HasError) { if (InvokeRequired) { WriteLineInvoke("No MX records found for host", Color.Gainsboro); Invoke(new Finished(WriteEmptyLine)); } } else { for (int i = 0; i < response.AllRecords.Count(); i++) { DnsResourceRecord record = response.AllRecords.ElementAt(i); MxRecord mxrecord = null; if (response.Answers.Count > i) { mxrecord = response.Answers.OfType <MxRecord>().ElementAt(i); } MXRecordCheck(record, mxrecord); } } } if (checkTXT) { var response = lookupClient.Query(host, QueryType.TXT); if (response.HasError) { WriteLineInvoke("No TXT records found for host", Color.Gainsboro); Invoke(new Finished(WriteEmptyLine)); } else { bool foundSpfRecord = false; bool spfIsValid = false; for (int i = 0; i < response.AllRecords.Count(); i++) { DnsResourceRecord record = response.AllRecords.ElementAt(i); TxtRecord txtrecord = null; if (response.Answers.Count > i) { txtrecord = response.Answers.OfType <TxtRecord>().ElementAt(i); } TXTRecordCheck(record, ref foundSpfRecord); if (record.ToString().Contains("spf1")) { spfIsValid = IsSPFValid(record.ToString()); } } if (!foundSpfRecord) { WriteLineInvoke("Warning: No SPF records found!", Color.OrangeRed); } else { if (!validateSPF) { WriteLineInvoke("Note: Use SPF Validation option to validate an SPF record", Color.Black); } else { if (spfIsValid) { WriteLineInvoke("SPF exists and is valid", Color.YellowGreen); } else { WriteLineInvoke("Warning: SPF exists, but doesn't appear valid", Color.OrangeRed); } } } } } if (InvokeRequired) { Invoke(new Finished(DnsCheckComplete)); UpdateStatusInvoke("Ready"); } })); runThread.Start(); button1.Text = "Cancel"; }