//public List<DnsRecord> Lookup //( // string szDomain, // UInt16 dnstype, // UInt32 querytype //) //{ // return HiddenLookup (ref szDomain, dnstype, querytype); //} private List <DnsRecord> HiddenLookup(string domain, DnsTypes dnstype, DnsQueryTypes querytype) { List <DnsRecord> records = null; try { UInt32 queryResultsSet = 0; if ((BypassCache) || (_dnsServer != null)) { querytype |= DnsQueryTypes.BypassCache; } byte[] data = null; if (_dnsServer != null) { data = new Byte [Marshal.SizeOf(typeof(UInt32)) * 2]; var memoryWriter = new BinaryWriter(new MemoryStream(data)); memoryWriter.Write((UInt32)1); byte [] address = _dnsServer.GetAddressBytes(); memoryWriter.Write(address); } uint dnsLookupResult = NativeMethods.DnsQuery(domain, (ushort)dnstype, (uint)querytype, data, ref queryResultsSet, 0); if (dnsLookupResult == 0) { records = new List <DnsRecord> (); var results = new IntPtr(queryResultsSet); do { var response = (ResponseStructure)Marshal.PtrToStructure(results, typeof(ResponseStructure)); DnsRecord newRecord = ResponseDecoder.Decode(results.ToInt32(), ref response); records.Add(newRecord); results = response.next; } while (results.ToInt32() != 0); if (records.Count > 0) { NativeMethods.DnsRecordListFree(ref queryResultsSet, 1); } } } catch (COMException) { } return(records); }
public static extern int DnsQuery([MarshalAs(UnmanagedType.VBByRefStr)] ref string pszName, DnsQueryTypes wType, DnsQueryOptions options, int aipServers, ref IntPtr ppQueryResults, int pReserved);