如何执行"nslookup主机服务器"

Rom*_*man 11 c# api nslookup

我的C#服务需要定期轮询nslookup host server.目前它产生了一个Process执行批处理脚本的程序.由于性能原因,我正在考虑使用一些进行此检查API.但问题是,使用,例如,System.Net.Dns.GetHostAddresses我只能模拟nslookup host检查,但不能nslookup host server(没有秒参数).

我看过一堆类似的SO问题,但似乎都没有解决我的问题.

有没有办法nslookup host serverC#没有使用一些沉重的第三方库的情况下执行?

Rom*_*man 12

问题解决了!

http://msdn.microsoft.com/en-us/library/ms682016(VS.85).aspx

请参阅" 此处的优秀示例 "部分

[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);

...
Run Code Online (Sandbox Code Playgroud)