Get PC and tablet physical address

Source: Internet
Author: User
Tags foreach trim

  This article mainly describes how to obtain PC and tablet physical address, need friends can refer to the following

Get PC Physical Address     namespace: Using system.management;    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: & nbsp   namespace:    using system.net;  using system.runtime.interopservices;    Add variable:    The code is as follows: protected static string strjavascript = String. empty;  [DllImport ("Iphlpapi.dll")]  private static extern int Sendarp (Int32 dest, Int32 host, ref Int64 Mac, re f Int32 length); &nBsp [DllImport ("Ws2_32.dll")]  private static extern Int32 inet_addr (string IP);      code as follows: private void S Etmac ()   {  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 don't have networking")   {  int iretn = commonws. GetInt ("crrt/pad-login", "Specify a flat MAC address for a treatment patient", new string[] {mac, treatment_id}); }  catch {} . innertext = "WW"; } }    private string Getmac ()   {  string mac = "";  string strclientip = Request.userhosta Ddress. ToString (). Trim ();  Int32 ldest = inet_addr (Strclientip); The destination of the ip  Int32 lhost = inet_addr (""); Local server 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;   }   

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.