/* This file is part of PacketDotNet PacketDotNet is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PacketDotNet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with PacketDotNet. If not, see . */ using System; using System.Net.NetworkInformation; using System.Text; namespace PacketDotNet.Utils { /// /// Helper class that prints out an array of hex values /// public class HexPrinter { /// /// Create a string that contains the hex values of byte[] Byte in /// text form /// /// /// A /// /// /// A /// /// /// A /// /// /// A /// public static string GetString(byte[] Byte, int Offset, int Length) { StringBuilder sb = new StringBuilder(); for(int i = Offset; i < Offset + Length; i++) { sb.AppendFormat("[{0:x2}]", Byte[i]); } return sb.ToString(); } /// /// Creates a string from a Physical address in the format "xx:xx:xx:xx:xx:xx" /// /// /// A /// /// /// A /// public static string PrintMACAddress(PhysicalAddress address) { byte[] bytes = address.GetAddressBytes(); string output = ""; for(int i = 0; i < bytes.Length; i++) { output += bytes[i].ToString("x").PadLeft(2, '0') + ":"; } return output.TrimEnd(':'); } } }