/// <summary>
        /// 获取请求机的mac地址
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetMac(this HttpRequestBase request)
        {
            string strmac = request.Headers.Get("mac");

            if (strmac.NotNullAndEmpty()) return strmac;

            if (strmac.IsNullOrEmpty())
            {
                var cookie = request.Cookies.Get("mac");
                if (cookie != null)
                    strmac = cookie.Value;
            }
            if (strmac.NotNullAndEmpty()) return strmac;

            if (strmac.IsNull()) strmac = "";

            // IPAddress.Parse(request.UserHostAddress).Address
            Int32 ldest = inet_addr(request.UserHostAddress);//目的地的ip
            Int32 lhost = 0;//本地的ip
            try
            {
                var macinfo = new Byte[6];
                uint length = 6;

                int ii = SendARP(ldest, lhost, macinfo, ref length);

                return macinfo.Aggregate(strmac, (current, item) => current + item.ToString("X2"));
            }
            catch (Exception err)
            {
                return "";
            }
        }
Beispiel #2
0
 /// <summary>
 /// Calculates CRC32 value for passsed byte array <paramref name="buffer"/> using
 /// initial value of <paramref name="crc"/> parameter as base for CRC calculation.
 /// </summary>
 public static UInt32 Compute(Byte[] buffer, UInt32 crc = 0)
 {
     return buffer.Aggregate(crc,
         (index, item) => _crcTable[((index >> 24) ^ item) & 0xFF] ^ (index << 8));
 }