Пример #1
0
 public void ParaseTest()
 {
     MacAddress expected = new MacAddress(0x00, 0x23, 0x33, 0x84, 0x1f, 0x40);
     MacAddress actual;
     actual = MacAddress.Parse("002333841f40");
     Assert.AreEqual(expected.ToString(), actual.ToString());
 }
Пример #2
0
        public void EditVoid()
        {
            byte[] bytes = new byte[] { 240, 1, 14, 239, 55, 55 };
            MacAddress expected = new MacAddress(bytes);
            var result = new System.Collections.Generic.Dictionary<MacAddress, string> {{expected, "ok"}};

            MacAddress target = new MacAddress(bytes);
            Assert.IsTrue(result.ContainsKey(target));
        }
Пример #3
0
 public void MacAddressConstructorTest1()
 {
     byte a = 1;
     byte b = 2;
     byte c = 3;
     byte d = 4;
     byte e = 5;
     byte f = 6;
     MacAddress target = new MacAddress(a, b, c, d, e, f);
 }
Пример #4
0
        /// <summary>
        /// 通过IPAddress 获取Mac地址,只是用于同网段
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        /// <exception cref="NetworkException">failed to get client mac</exception>
        public static MacAddress GetMac(this IPAddress client)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            try
            {
                int ldest = inet_addr(client.ToString()); //目的地的ip

                var    macinfo = new Int64();
                int    len     = 6;
                int    res     = SendARP(ldest, 0, ref macinfo, ref len);
                string macSrc  = macinfo.ToString("X");
                string macDest = "";

                while (macSrc.Length < 12)
                {
                    macSrc = macSrc.Insert(0, "0");
                }
                for (int i = 0; i < 11; i++)
                {
                    if (0 == (i % 2))
                    {
                        macDest = i == 10
                                      ? macDest.Insert(0, macSrc.Substring(i, 2))
                                      : "-" + macDest.Insert(0, macSrc.Substring(i, 2));
                    }
                }
                return(MacAddress.Parse(macDest));
            }
            catch (Exception ex)
            {
                throw new NetworkException(String.Format("Can't find mac from {0}", client), ex);
            }
        }
Пример #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(MacAddress other)
 {
     return Equals(other._taken, _taken);
 }
Пример #6
0
 public bool Equals(MacAddress other)
 {
     return(Equals(other._taken, _taken));
 }
Пример #7
0
 public void ToStringTest()
 {
     byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6 };
     MacAddress target = new MacAddress(bytes);
     string expected = "01-02-03-04-05-06";
     string actual;
     actual = target.ToString();
     Assert.AreEqual(expected, actual);
 }
Пример #8
0
        public void ParseTest()
        {
            string mac = "F0-01-0E-EF-37-37";

            byte[] bytes = new byte[] { 240, 1, 14, 239, 55, 55 };
            MacAddress expected = new MacAddress(bytes);

            MacAddress actual = MacAddress.Parse(mac);
            Assert.AreEqual(expected, actual);
        }