Skip to content

getHostsCount()

Evgheniy Kovaliov edited this page May 10, 2023 · 3 revisions

getHostsCount(prefix)

Description

Method that allows you get total number of hosts in ip network by prefix.
Ip prefix must be correct. (see validation)

Contract

Parameters:

  • prefix: number — ip prefix.

Return:

  • number — number of hosts.
Exceptions

Invalide ip prefix!:

  • entered argument is not a correct ip prefix.
Usage
ipv4.getHostsCount(32);             // 1
ipv4.getHostsCount(0);              // 4294967296
ipv4.getHostsCount(31);             // 2
ipv4.getHostsCount(16);             // 65536
ipv4.getHostsCount(4);              // 268435456
ipv4.getHostsCount(25;              // 128

ipv4.getHostsCount('25');           // Error: Invalide prefix entered!
ipv4.getHostsCount('128.64.0.0/8'); // Error: Invalide prefix entered!
ipv4.getHostsCount([16]);           // Error: Invalide prefix entered!
ipv4.getHostsCount(false);          // Error: Invalide prefix entered!

MAIN PAGE

See all methods documentation:

For ip version 4

For ip version 6

Clone this wiki locally