从注册表中找到dns服务器的方法
public class cxyDns
...{
public static string[] GetDns()
...{
RegistryKey m_machine=Registry.LocalMachine;
string m_dnskey=@"SYSTEMCurrentControlSetServicesTcpipParameters";
RegistryKey m_dnsKey=m_machine.OpenSubKey(m_dnskey);
if(m_dnsKey==null)
...{
throw new Exception("不能打开dns键位");
}
string m_nameServer=m_dnsKey.GetValue("DhcpNameServer").ToString();
m_dnsKey.Close();
m_machine.Close();
//清理使用的资源
char[] token=new char[1];
token[0]=' ';
string[] m_dnslist=m_nameServer.Split(token);
return m_dnslist;
}
}
时间: 2024-09-14 09:44:41