获取IP并写入hosts文件
1
String ss = "要获取IP的域名";
2
IPHostEntry hostInfo = Dns.GetHostByName(ss);
3
IPAddress ip = hostInfo.AddressList[0];
4
textIP.Text = ip.ToString();
5
StreamWriter sw = new StreamWriter ("C:\\Windows\\System32\\Drivers\\etc\\hosts");
6
sw.WriteLine(ip.ToString() + "\0映射的地址");
7
sw.Close();
String ss = "要获取IP的域名";2
IPHostEntry hostInfo = Dns.GetHostByName(ss);3
IPAddress ip = hostInfo.AddressList[0];4
textIP.Text = ip.ToString();5
StreamWriter sw = new StreamWriter ("C:\\Windows\\System32\\Drivers\\etc\\hosts");6
sw.WriteLine(ip.ToString() + "\0映射的地址");7
sw.Close();
浙公网安备 33010602011771号