Get PC and Tablet Physical Address _ practical Tips

Source: Internet
Author: User
Get PC Physical Address

namespaces: Using System.Management;
Copy Code code as follows:

<summary>
Get Mac Physical Address
</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 "";
}
}

Get flat MAC Address:

Namespaces:

Using System.Net;
Using System.Runtime.InteropServices;

To add a variable:
Copy Code code as follows:

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);

Copy Code code as follows:

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!= "You are not networked")
{
int iretn = COMMONWS. GetInt ("crrt/pad-login", "Specify a flat MAC address for a patient to be treated", 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 of destination
Int32 lhost = inet_addr (""); IP for local server
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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.