获取IP并写入hosts文件

 

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

 

posted @ 2009-07-22 20:16  錯咗  阅读(1025)  评论(0编辑  收藏  举报