How to perform "nslookup host server"
Solution 1
The problem was solved!
http://msdn.microsoft.com/en-us/library/ms682016(VS.85).aspx
See "Great Example here" section
[DllImport("dnsapi", EntryPoint="DnsQuery_W", CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
private static extern int DnsQuery([MarshalAs(UnmanagedType.VBByRefStr)]ref string pszName, QueryTypes wType, QueryOptions options, int aipServers, ref IntPtr ppQueryResults, int pReserved);
[DllImport("dnsapi", CharSet=CharSet.Auto, SetLastError=true)]
private static extern void DnsRecordListFree(IntPtr pRecordList, int FreeType);
...
Solution 2
I looked into this a while back. It is not possible in the standard class libraries, so you are going to have to use an external component to do this properly.
There are a number of free and paid choices available to you. My implementation was based around a posting on CodeProject, which worked quite well. DNS Client Library for .NET (also mentioned by kprobst) was released after I finished mine, or I would've used this one initially.
Related videos on Youtube
Comments
-
Roman almost 2 years
My
C#
service needs to periodically pollnslookup host server
. Currently it spawns aProcess
that executes batch script. Due to performance reason I'm considering to do this check using someAPI
. But the problem is, that using, for example,System.Net.Dns.GetHostAddresses
I can only emulatenslookup host
check, but notnslookup host server
(without seconds param).I've looked at bunch of similar SO questions, but none of them seem to solve my issue.
Are there any way to perform
nslookup host server
inC#
without using some heavy third-patry library? -
Klom Dark over 4 yearsUnfortunately the "Great Example here" section is no longer present on the msdn url you posted. Know of any other ways to accomplish 'nslookup host server'?