|
2 | 2 | using System; |
3 | 3 | using System.Net; |
4 | 4 | using System.Threading.Tasks; |
5 | | -using System.Windows; |
6 | 5 |
|
7 | 6 | namespace NETworkManager.Models.Network |
8 | 7 | { |
@@ -67,41 +66,54 @@ public void LookupAsync(string hostnameOrIPAddress, DNSLookupOptions dnsLookupOp |
67 | 66 | OnLookupError(new DNSLookupErrorArgs(dnsResponse.Error)); |
68 | 67 | return; |
69 | 68 | } |
| 69 | + |
| 70 | + // Process the results... |
| 71 | + ProcessResponse(dnsResponse); |
70 | 72 |
|
71 | | - // A |
72 | | - foreach (RecordA r in dnsResponse.RecordsA) |
73 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 73 | + // If we get a CNAME back (from a result), do a second request and try to get the A, AAAA etc... |
| 74 | + if(dnsLookupOptions.Type != QType.CNAME) |
| 75 | + { |
| 76 | + foreach(RecordCNAME r in dnsResponse.RecordsCNAME) |
| 77 | + ProcessResponse(dnsResolver.Query(r.CNAME, dnsLookupOptions.Type, dnsLookupOptions.Class)); |
| 78 | + } |
| 79 | + |
| 80 | + OnLookupComplete(); |
| 81 | + }); |
| 82 | + } |
74 | 83 |
|
75 | | - // AAAA |
76 | | - foreach (RecordAAAA r in dnsResponse.RecordsAAAA) |
77 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 84 | + private void ProcessResponse(Response dnsResponse) |
| 85 | + { |
| 86 | + // A |
| 87 | + foreach (RecordA r in dnsResponse.RecordsA) |
| 88 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
78 | 89 |
|
79 | | - // CNAME |
80 | | - foreach (RecordCNAME r in dnsResponse.RecordsCNAME) |
81 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 90 | + // AAAA |
| 91 | + foreach (RecordAAAA r in dnsResponse.RecordsAAAA) |
| 92 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
82 | 93 |
|
83 | | - // MX |
84 | | - foreach (RecordMX r in dnsResponse.RecordsMX) |
85 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 94 | + // CNAME |
| 95 | + foreach (RecordCNAME r in dnsResponse.RecordsCNAME) |
| 96 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
86 | 97 |
|
87 | | - // NS |
88 | | - foreach (RecordNS r in dnsResponse.RecordsNS) |
89 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 98 | + // MX |
| 99 | + foreach (RecordMX r in dnsResponse.RecordsMX) |
| 100 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
90 | 101 |
|
91 | | - // PTR |
92 | | - foreach (RecordPTR r in dnsResponse.RecordsPTR) |
93 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 102 | + // NS |
| 103 | + foreach (RecordNS r in dnsResponse.RecordsNS) |
| 104 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
94 | 105 |
|
95 | | - // SOA |
96 | | - foreach (RecordSOA r in dnsResponse.RecordsSOA) |
97 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 106 | + // PTR |
| 107 | + foreach (RecordPTR r in dnsResponse.RecordsPTR) |
| 108 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
98 | 109 |
|
99 | | - // TXT |
100 | | - foreach (RecordTXT r in dnsResponse.RecordsTXT) |
101 | | - OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString())); |
| 110 | + // SOA |
| 111 | + foreach (RecordSOA r in dnsResponse.RecordsSOA) |
| 112 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
102 | 113 |
|
103 | | - OnLookupComplete(); |
104 | | - }); |
| 114 | + // TXT |
| 115 | + foreach (RecordTXT r in dnsResponse.RecordsTXT) |
| 116 | + OnRecordReceived(new DNSLookupRecordArgs(r.RR, r.ToString().TrimEnd())); |
105 | 117 | } |
106 | 118 | #endregion |
107 | 119 | } |
|
0 commit comments