C#获取本机信息
当前位置:知识管理交流
→『 技术文档交流 』
/// <summary>
/// 获得本机IP
/// </summary>
/// <returns></returns>
public string GetIP()
{
string IP = null;
string hostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(hostName);
foreach (IPAddress ip in ipEntry.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
IP = ip.ToString();
}
}
return IP;
}
/// <summary>
/// 获得本机Mac
/// </summary>
/// <returns></returns>
public string GetMac()
{
string mac = null;
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
if (interfaces.Length > 0)
{
mac = interfaces[0].GetPhysicalAddress().ToString();
if (mac.Length > 21)
{
mac = mac.Substring(0, 21);
}
}
return mac;
}
/// <summary>
/// 获取系统版本
/// </summary>
/// <returns></returns>
public string GetOSVersion()
{
OperatingSystem osInfo = Environment.OSVersion;
string version = osInfo.Version.ToString();
return version;
}
/// <summary>
/// 获得系统分辨率
/// </summary>
/// <returns></returns>
public string GetResolution()
{
int SW = Screen.PrimaryScreen.Bounds.Width;
int SH = Screen.PrimaryScreen.Bounds.Height;
string resolution = SW.ToString() + "*" SH.ToString();
return resolution;
}
该文章在 2021/1/29 17:06:24 编辑过 |
关键字查询
相关文章
正在查询... |