问题描述
我的 C#
服务需要定期轮询 Nslookup的主机服务器
。目前,它生成一个过程
的执行批处理脚本。由于性能原因,我正在考虑使用一些 API
做此项检查。但问题是,在使用,例如, System.Net.Dns.GetHostAddresses
我只能模仿 NSLOOKUP主机
检查一下,但不是 Nslookup的主机服务器
(不含秒参数)。
My C#
service needs to periodically poll nslookup host server
. Currently it spawns a Process
that executes batch script. Due to performance reason I'm considering to do this check using some API
. But the problem is, that using, for example, System.Net.Dns.GetHostAddresses
I can only emulate nslookup host
check, but not nslookup host server
(without seconds param).
我看着一堆类似SO问题,但他们都不来解决我的问题。
I've looked at bunch of similar SO questions, but none of them seem to solve my issue.
还有什么办法来执行 C#
Nslookup的主机服务器
不使用一些重型第三PATRY库?
Are there any way to perform nslookup host server
in C#
without using some heavy third-patry library?
推荐答案
问题解决了!
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);
...
这篇关于如何执行" Nslookup的主机服务器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!