• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

获取pc电脑和平板物理地址

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
获取pc物理地址

命名空间:using System.Management;
复制代码 代码如下:

/// <summary>
/// 获取mac物理地址
/// </summary>
/// <returns></returns>
public string GetMac()
{
try
{
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
if (mo["IPEnabled"].ToString() == "True")
return mo["MacAddress"].ToString();
}
return "";
}
catch
{
return "";
}
}

获取平板mac地址:

命名空间:

using System.Net;
using System.Runtime.InteropServices;

添加变量:
复制代码 代码如下:

protected static string strJavaScript = string.Empty;
[DllImport("Iphlpapi.dll")]
private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);

复制代码 代码如下:

private void SetMac()
{
try
{
string treatment_id = Hid_treatment_id.Value;
string mac = string.Empty;

string ip = Request.UserHostAddress.ToString().Trim();
try
{
mac = getMac();
}
catch { lbl.InnerText = "w33w"; }
//mac = "00:01:36:D8:9C:C4";
// lbl.InnerText = mac + "," + ip;
if (mac != "您没有联网")
{
int iRetn = commonws.GetInt("CRRT/PAD-登录", "指定某治疗病人的平板MAC地址", new string[] { mac, treatment_id });
}
}
catch { lbl.InnerText = "ww"; }
}

private string getMac()
{
string mac = "";
string strClientIP = Request.UserHostAddress.ToString().Trim();
Int32 ldest = inet_addr(strClientIP); //目的地的ip
Int32 lhost = inet_addr(""); //本地服务器的ip
Int64 macinfo = new Int64();
Int32 len = 6;
int res = SendARP(ldest, 0, ref macinfo, ref len);
mac = macinfo.ToString("X");
try
{
string[] arr_mac = new string[mac.Length / 2];
int k = 0;
for (int i = mac.Length; i > 0; i = i - 2)
{
arr_mac[k] = mac.Substring(i - 2, 2);
k++;
}
mac = "";
foreach (string chars in arr_mac)
{
mac += chars + ":";
}
mac = mac.TrimEnd(':');
}
catch { }
return mac;

}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
html+ashx 表单提交示例发布时间:2022-02-05
下一篇:
gridview 行选添加颜色和事件发布时间:2022-02-05
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap