獲取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 != "您沒(méi)有聯(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 != "您沒(méi)有聯(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)文章
asp.net core webapi 服務(wù)端配置跨域的實(shí)例
下面小編就為大家分享一篇asp.net core webapi 服務(wù)端配置跨域的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
asp.net core razor自定義taghelper的方法
這篇文章主要介紹了asp.net core razor自定義taghelper的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
.Net Core配置與自動(dòng)更新的實(shí)現(xiàn)方法
下面小編就為大家分享一篇.Net Core配置與自動(dòng)更新的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
通過(guò)RadioButton對(duì)DataList控件進(jìn)行單選實(shí)例說(shuō)明
本例實(shí)現(xiàn)通過(guò)RadioButton對(duì)DataList控件進(jìn)行單選,aspx拉一個(gè)DataList控件,把RadioButton置于DataList的ItemTemplate模版內(nèi);在.aspx.cs內(nèi)為DataList控件綁定數(shù)據(jù),很實(shí)用的功能,感興趣的朋友可以了解下啊2013-01-01
asp.net異步獲取datatable并顯示的實(shí)現(xiàn)方法
這篇文章主要介紹了asp.net異步獲取datatable并顯示的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了asp.net一步操作datatable的相關(guān)技巧,需要的朋友可以參考下2016-03-03
asp.net sqlconnection con.close和con.dispose區(qū)別
con.close是用來(lái)關(guān)閉和數(shù)據(jù)庫(kù)的連接,相對(duì)于open2008-12-12
asp.net 獲取TreeView中第一個(gè)選中的節(jié)點(diǎn)
今天做的項(xiàng)目中有一個(gè)要獲取TreeView中第一個(gè)選中的節(jié)點(diǎn),當(dāng)然子節(jié)點(diǎn)己包含checkbox以前做過(guò),用的時(shí)候又不知道怎么做了,花了點(diǎn)時(shí)間又寫(xiě)了一下,記錄下來(lái),以備下次用.2010-03-03
xls表格導(dǎo)入數(shù)據(jù)庫(kù)功能實(shí)例代碼
這篇文章介紹了xls表格導(dǎo)入數(shù)據(jù)庫(kù)功能實(shí)例代碼,有需要的朋友可以參考一下2013-10-10

