Answers for "ips in range typescript"

0

ips in range typescript

// Returns the number of ips between ip1 and ip2
function ipsInRange(ip1: string, ip2: string): number {

  const ip1Bin: string = ip1.split('.').map((p) => parseInt(p).toString(2).padStart(8, '0')).join('');
  const ip2Bin: string = ip2.split('.').map((p) => parseInt(p).toString(2).padStart(8, '0')).join('');

  return parseInt(ip2Bin, 2) - parseInt(ip1Bin, 2);
}
Posted by: Guest on March-03-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language