您好,登錄后才能下訂單哦!
本篇內容主要講解“如何獲取pc電腦和平板物理地址”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何獲取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 != "您沒有聯網")
{
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;
}
到此,相信大家對“如何獲取pc電腦和平板物理地址”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。