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

所属分类: 网络编程 / ASP.NET 阅读数: 1464
收藏 0 赞 0 分享
获取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;

}
更多精彩内容其他人还在看

C#中Dictionary几种遍历的实现代码

C#中Dictionary几种遍历的实现代码,需要的朋友可以参考一下
收藏 0 赞 0 分享

C#实现EXCEL数据到TXT文档的转换

C#实现EXCEL数据到TXT文档的转换,需要的朋友可以参考一下
收藏 0 赞 0 分享

C#数据绑定控件中的DataSource属性浅谈

使用该属性指定用来填充Repeater控件的数据源。DataSource可以是任何System.Collections.IEnumerable对象, 如用于访问数据库的System.Data.DataView、System.Collections.ArrayList、Syste
收藏 0 赞 0 分享

ASP.Net开发常见的一些问题总结

ASP.Net开发常见的一些问题总结,需要的朋友可以参考一下
收藏 0 赞 0 分享

Log4net日志记录组件的使用步骤详解和下载

Log4net日志记录组件的使用步骤详解,需要的朋友可以参考一下
收藏 0 赞 0 分享

ASP.NET主机资源控制的一些心得

您可以通过以下设置控制ASP.NET主机对服务器内存的占用。并能设置ASP.NET主机进程定时重建这样可以避免服务器长时间运行aspnet占用大量空闲内存,有利于提高aspnet运行效率。
收藏 0 赞 0 分享

ADO与ADO.NET的区别与介绍

ADO与ADO.NET简介ADO与ADO.NET既有相似也有区别
收藏 0 赞 0 分享

Asp.Net各种超时问题总结

在数据库或者请求操作时,如果选择的时间段过短或操作数据量过大,就会遇到"请求超时"的的问题,网络上提供很多解决方案,但普遍不完善,根据个人经验及参考网络解决方案,先将其汇总
收藏 0 赞 0 分享

vs.net2008添加模板方法

vs.net2008添加模板方法,需要的朋友可以参考一下
收藏 0 赞 0 分享

Asp.net后台把脚本样式输出到head标签中节省代码冗余

最近在学习开发服务器控件,其它就少不了为控件注册js和css之类的资源文件,或者直接注册纯脚本样式。其中就遇到如下问题     1、 注册的资源文件或纯脚本样式在生成的页面中都不在head标签中(当然这个不影响页面功能)     2、 一个页面使用多个一样的控件时,会
收藏 0 赞 0 分享
查看更多