52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
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<IPAddress> 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<string, string> kvp in replacementPairs)
|
|
result.Replace(kvp.Key, kvp.Value);
|
|
|
|
return result.ToString();
|
|
}
|
|
|
|
private static Dictionary<string, string> replacementPairs = new Dictionary<string, string>()
|
|
{
|
|
["\n"] = @"\n",
|
|
["\t"] = @"\t"
|
|
};
|
|
|
|
/// <summary>
|
|
/// Concatenates a pair of buffers into a single long buffer.
|
|
/// </summary>
|
|
/// <param name="A">The first buffer to concatenate.</param>
|
|
/// <param name="B">The second buffer to concatenate.</param>
|
|
/// <returns>The concatenated buffers.</returns>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|