-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
26 lines (23 loc) · 735 Bytes
/
Util.cs
File metadata and controls
26 lines (23 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Net;
namespace TheDirector;
public static class Util
{
public static uint GetIPAddressAsUInt(string ipAddress)
{
if (string.IsNullOrEmpty(ipAddress))
throw new ArgumentException(nameof(ipAddress));
var address = IPAddress.Parse(ipAddress);
var bytes = address.GetAddressBytes();
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);
return BitConverter.ToUInt32(bytes, 0);
}
public static string GetUIntAsIPAddress(uint ip)
{
var bytes = BitConverter.GetBytes(ip);
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);
var address = new IPAddress(bytes);
return address.ToString();
}
}