using System; using System.Collections; using System.Net; using System.Linq; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; namespace SBRL.Utilities { public static class Utilities { public static IEnumerable GetLocalIps() { IPHostEntry entries = Dns.GetHostEntry(Dns.GetHostName()); return (from ipAddr in entries.AddressList where !IPAddress.IsLoopback(ipAddr) select ipAddr).ToList(); } public static string EscapeString(string str) { StringBuilder result = new StringBuilder(str); foreach(KeyValuePair kvp in replacementPairs) result.Replace(kvp.Key, kvp.Value); return result.ToString(); } private static Dictionary replacementPairs = new Dictionary() { ["\n"] = @"\n", ["\t"] = @"\t" }; /// /// Concatenates a pair of buffers into a single long buffer. /// /// The first buffer to concatenate. /// The second buffer to concatenate. /// The concatenated buffers. public static byte[] ConcatBuffers(byte[] A, byte[] B) { byte[] result = new byte[A.Length + B.Length]; Buffer.BlockCopy(A, 0, result, 0, A.Length); Buffer.BlockCopy(B, 0, result, A.Length, B.Length); return result; } } }