/[AnywhereTS-MSSQL]/branches/TerminalServices/AnywhereTS.Extensions/IPAddressExtensions.cs
ViewVC logotype

Contents of /branches/TerminalServices/AnywhereTS.Extensions/IPAddressExtensions.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations) (download)
Sun Aug 26 00:04:01 2012 UTC (8 years, 1 month ago) by william
File size: 1294 byte(s)
+ switch TerminalServices backend to Cassia 2.0.0.60

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Runtime.InteropServices;
6 using System.Net;
7
8 namespace AnywhereTS.Extensions
9 {
10 public static class IPAddressExtensions
11 {
12 // For Lookup of MAC address
13 [DllImport("iphlpapi.dll", ExactSpelling = true)]
14 private static extern int SendARP(int DestIP, int SrcIP, [Out] byte[]
15 pMacAddr, ref int PhyAddrLen);
16 public static string ToMacAddress(this System.Net.IPAddress address)
17 {
18 int rv;
19 string macStr;
20 byte[] mac = new byte[6];
21 int maclen = mac.Length;
22
23 rv = SendARP(BitConverter.ToInt32(address.GetAddressBytes(), 0), 0, mac, ref maclen);
24 if (rv == 0) // If not 0, error
25 {
26 // macStr = BitConverter.ToString(mac, 0, 6);
27 macStr = BitConverter.ToString(mac, 0, 1) + BitConverter.ToString(mac, 1, 1) + BitConverter.ToString(mac, 2, 1)
28 + BitConverter.ToString(mac, 3, 1) + BitConverter.ToString(mac, 4, 1) + BitConverter.ToString(mac, 5, 1);
29 }
30 else
31 {
32 macStr = "";
33 }
34 return macStr;
35 }
36 }
37 }

  ViewVC Help
Powered by ViewVC 1.1.22