How to get windows dns suffix serach list from ip configuration using c++ ? (.NET <= 3.5)
You can get them from the registry.
If set from the network control panel:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\SearchList
If set by Group Policy:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\SearchList
Use the Registry class to read , the same class can be use set but, you will need admin permissions to do so.
C# using Management and WMI Classes:
ManagementObjectSearcher q= new ManagementObjectSearcher("SELECT ServiceName,DNSDomainSuffixSearchOrder FROM Win32_NetworkAdapterConfiguration");// WHERE DNSDomainSuffixSearchOrder IS NOT NULL");
var qc= q.Get();
foreach (ManagementObject mo in qc)
{
if ( mo.Properties["DNSDomainSuffixSearchOrder"] != null)
{
var s = mo.Properties["DNSDomainSuffixSearchOrder"];
if (s.Value != null)
{
Console.WriteLine(mo["ServiceName"]);
string[] sfxNames = s.Value as string[];
foreach (string sx in sfxNames)
{
Console.WriteLine(sx);
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.