mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
25 lines
619 B
C#
25 lines
619 B
C#
using System.Net;
|
|
|
|
namespace IP2Region.Net.XDB;
|
|
|
|
public static class Util
|
|
{
|
|
public static uint IpAddressToUInt32(string ipAddress)
|
|
{
|
|
var address = IPAddress.Parse(ipAddress);
|
|
return IpAddressToUInt32(address);
|
|
}
|
|
|
|
public static uint IpAddressToUInt32(IPAddress ipAddress)
|
|
{
|
|
byte[] bytes = ipAddress.GetAddressBytes();
|
|
Array.Reverse(bytes);
|
|
return BitConverter.ToUInt32(bytes, 0);
|
|
}
|
|
|
|
public static uint GetMidIp(uint x, uint y)
|
|
=> (x & y) + ((x ^ y) >> 1);
|
|
|
|
public static int GetMidIp(int x, int y)
|
|
=> (x & y) + ((x ^ y) >> 1);
|
|
} |