IP Address Integer Format
Some API fields use signed 32-bit integers for IPv4 addresses, for example:
ipAddressfromGET /api/v1/serversipAddressfromGET /api/v1/servers/{ip}/{port}currentServerIpfromGET /api/v1/playersserver.ipAddressfromGET /api/v1/players/{uuid}/sessions
Why signed? PostgreSQL integer is signed 32-bit, so addresses >= 128.0.0.0 appear as negative values.
Conversion logic
Section titled “Conversion logic”- Convert the signed value to an unsigned 32-bit integer.
- Split into 4 octets using bit shifts and masks.
- Join octets with dots.
Conversion examples
Section titled “Conversion examples”function intToIp(ipInt) { const unsigned = ipInt >>> 0; return [ (unsigned >>> 24) & 255, (unsigned >>> 16) & 255, (unsigned >>> 8) & 255, unsigned & 255 ].join('.');}
console.log(intToIp(16909060)); // 1.2.3.4console.log(intToIp(-939524096)); // 200.0.0.0def int_to_ip(ip_int: int) -> str: unsigned = ip_int & 0xFFFFFFFF return ".".join( str((unsigned >> shift) & 0xFF) for shift in (24, 16, 8, 0) )
print(int_to_ip(16909060)) # 1.2.3.4print(int_to_ip(-939524096)) # 200.0.0.0public static String intToIp(int ipInt) { long unsigned = Integer.toUnsignedLong(ipInt); return String.format( "%d.%d.%d.%d", (unsigned >>> 24) & 255, (unsigned >>> 16) & 255, (unsigned >>> 8) & 255, unsigned & 255 );}
System.out.println(intToIp(16909060)); // 1.2.3.4System.out.println(intToIp(-939524096)); // 200.0.0.0