獲取pc電腦和平板物理地址
更新時(shí)間:2014年03月22日 18:16:29 作者:
這篇文章主要介紹了如何獲取pc電腦和平板物理地址,需要的朋友可以參考下
獲取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 != "您沒有聯(lián)網(wǎng)")
{
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(""); //本地服務(wù)器的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;
}
命名空間:using System.Management;
復(fù)制代碼 代碼如下:
/// <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;
添加變量:
復(fù)制代碼 代碼如下:
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);
復(fù)制代碼 代碼如下:
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 != "您沒有聯(lián)網(wǎng)")
{
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(""); //本地服務(wù)器的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;
}
相關(guān)文章
.Net語(yǔ)言Smobiler開發(fā)之如何在手機(jī)上實(shí)現(xiàn)表單設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了.Net語(yǔ)言APP開發(fā)平臺(tái),如何在手機(jī)上實(shí)現(xiàn)表單設(shè)計(jì)(Smobiler),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Asp.net Core中實(shí)現(xiàn)自定義身份認(rèn)證的示例代碼
這篇文章主要介紹了Asp.net Core中實(shí)現(xiàn)自定義身份認(rèn)證的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05Visual Studio 2017下ASP.NET CORE的TagHelper智能提示解決辦法
這篇文章主要為大家詳細(xì)介紹了Visual Studio 2017下ASP.NET CORE TagHelper智能提示的解決辦法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03asp.net 無(wú)刷新翻頁(yè)就是這么簡(jiǎn)單
前兩天看了一個(gè)自定義分頁(yè)控件,和AspNetPager一樣是實(shí)現(xiàn)IPostBackEventHandler接口,不過(guò)簡(jiǎn)潔許多,就想能不能實(shí)現(xiàn)ICallbackEventHandler接口做到無(wú)刷新分頁(yè)呢?想到了就馬上去做,終于,設(shè)想變成了現(xiàn)實(shí)??!2010-03-03ASP.NET框架中的數(shù)據(jù)綁定概要與數(shù)據(jù)綁定表達(dá)式的使用
數(shù)據(jù)綁定是ASP.NET中操作數(shù)據(jù)的基礎(chǔ)方式,這里我們暫時(shí)拋開.NET提供的控件,來(lái)從基礎(chǔ)上講解ASP.NET框架中的數(shù)據(jù)綁定概要與數(shù)據(jù)綁定表達(dá)式的使用:2016-06-06asp.net基礎(chǔ)學(xué)習(xí)之控件的使用方法
這篇文章主要為大家詳細(xì)介紹了asp.net基礎(chǔ)學(xué)習(xí)之控件的使用方法,感興趣的小伙伴們可以參考一下2016-08-08asp.net利用ashx文件實(shí)現(xiàn)文件的上傳功能
這篇文章主要介紹了asp.net利用ashx文件實(shí)現(xiàn)文件的上傳功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11