一,先创建一个类,代码可以直接用,需要添加引用,直接添加就行
/// <summary>
/// 获取本地IP
/// </summary>
/// <returns></returns>
public static string Get_UserIP()
{
string ip = "";
string strHostName = Dns.GetHostName(); //得到本机的主机名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
if (ipEntry.AddressList.Length > 0)
{
ip = ipEntry.AddressList[0].ToString();
}
return ip;
//string userip = "";
//string name = Dns.GetHostName();
//IPAddress[] ips = Dns.GetHostAddresses(name);
//foreach (IPAddress ip in ips)
// userip += ip.ToString() + "|";//所有IP
//return userip;
}
/// <summary>
/// 获取CPU信息
///