Esempio n. 1
0
 public static string GetMac()
 {
     try
     {
         string userHostAddress = HttpContext.Current.Request.UserHostAddress;
         string ip   = HttpContext.Current.Request.UserHostAddress.ToString().Trim();
         int    dest = IPHelp.inet_addr(ip);
         IPHelp.inet_addr(ip);
         long mac    = 0;
         int  length = 6;
         IPHelp.SendARP(dest, 0, ref mac, ref length);
         string str1 = mac.ToString("X");
         if (str1 == "0")
         {
             return("错误");
         }
         while (str1.Length < 12)
         {
             str1 = str1.Insert(0, "0");
         }
         string str2 = "";
         for (int startIndex = 0; startIndex < 11; ++startIndex)
         {
             if (startIndex % 2 == 0)
             {
                 str2 = startIndex != 10 ? "-" + str2.Insert(0, str1.Substring(startIndex, 2)) : str2.Insert(0, str1.Substring(startIndex, 2));
             }
         }
         return(str2);
     }
     catch (Exception ex)
     {
         return(ex.ToString());
     }
 }
Esempio n. 2
0
        public static string GetMac()
        {
            string result = "";

            try
            {
                string arg_15_0 = HttpContext.Current.Request.UserHostAddress;
                string ip       = HttpContext.Current.Request.UserHostAddress.ToString().Trim();
                int    dest     = IPHelp.inet_addr(ip);
                IPHelp.inet_addr(ip);
                long num  = 0L;
                int  num2 = 6;
                IPHelp.SendARP(dest, 0, ref num, ref num2);
                string text = num.ToString("X");
                if (text == "0")
                {
                    return("错误");
                }
                while (text.Length < 12)
                {
                    text = text.Insert(0, "0");
                }
                string text2 = "";
                for (int i = 0; i < 11; i++)
                {
                    if (i % 2 == 0)
                    {
                        if (i == 10)
                        {
                            text2 = text2.Insert(0, text.Substring(i, 2));
                        }
                        else
                        {
                            text2 = "-" + text2.Insert(0, text.Substring(i, 2));
                        }
                    }
                }
                result = text2;
            }
            catch (Exception ex)
            {
                result = ex.ToString();
            }
            return(result);
        }