UNPKG

netkitty

Version:
22 lines (21 loc) 665 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BufferToIPv4 = BufferToIPv4; exports.BufferToIPv6 = BufferToIPv6; const ip_address_1 = require("ip-address"); /** * Convert Buffer to IPv4 string * @param buffer * @constructor */ function BufferToIPv4(buffer) { return ip_address_1.Address4.fromBigInt(BigInt(`0x${Buffer.alloc(4, buffer).toString('hex').padStart(8, '0')}`)).address; } /** * Convert Buffer to IPv6 string * @param buffer * @constructor */ function BufferToIPv6(buffer) { return ip_address_1.Address6.fromBigInt(BigInt(`0x${Buffer.alloc(16, buffer).toString('hex').padStart(32, '0')}`)).address; }