UNPKG

request-public-ip

Version:

Node.js module for retrieving a request's public IP address

19 lines (14 loc) 542 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var parser$1 = require('./parser.js'); // See https://stackoverflow.com/questions/166132/maximum-length-of-the-textual-representation-of-an-ipv6-address const MAX_IPV6_LENGTH = 45; const parser = new parser$1.Parser(); /** Parse `input` into IPv4 or IPv6 bytes. */ function parseIP(input) { if (input.length > MAX_IPV6_LENGTH) { return undefined; } return parser.new(input).parseWith(() => parser.readIPAddr()); } exports.parseIP = parseIP;