How to perform “nslookup host server”

前端 未结 3 1277
[愿得一人]
[愿得一人] 2020-11-30 13:47

My C# service needs to periodically poll nslookup host server. Currently it spawns a Process that executes batch script. Due to perfor

相关标签:
3条回答
  • 2020-11-30 14:18

    I'm not sure how to do this using the framework directly because I've never needed to use a DNS server different than the one specified in the local machine configuration. But you might want to give this library a try. I've never used it but as far as I can tell it will allow you to specify a DNS server to use in resolving the host name you pass.

    0 讨论(0)
  • 2020-11-30 14:22

    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.

    0 讨论(0)
  • 2020-11-30 14:30

    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);
    
    ...
    
    0 讨论(0)
提交回复
热议问题