UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

14 lines (13 loc) 353 B
export function isValidIPv4(ip) { return /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/.test(ip); } export function ipToUnsignedInteger(ip) { const ipUnsigned = ip .split('.') .map((octet) => parseInt(octet)) .reduce((a, b) => a * 256 + b); if (isNaN(ipUnsigned)) { return null; } return ipUnsigned; }