-
Notifications
You must be signed in to change notification settings - Fork 0
getNetworkAddress()
Evgheniy Kovaliov edited this page May 10, 2023
·
3 revisions
Method that allows you get ip network that contains entered ip address in X.X.X.X/PREF format, where X.X.X.X is network address and PREF is prefix.
Ip address and prefix must be correct. (see validation)
Parameters:
-
ip: string— ip address. -
mask: string— subnet mask.
Return:
-
network: string— network that contains entered ip address.
Invalide ip address!:
- entered argument is not a correct ip address.
Invalide subnet mask!:
- entered argument is not a correct subnet mask.
ipv4.getNetworkAddress('0.0.0.0', '0.0.0.0'); // '0.0.0.0/0'
ipv4.getNetworkAddress('255.255.255.255', '255.255.255.255'); // '255.255.255.255/32'
ipv4.getNetworkAddress('255.255.255.255', '0.0.0.0'); // '255.255.255.255/32'
ipv4.getNetworkAddress('34.100.255.45', '255.255.252.0'); // '34.100.252.0/22'
ipv4.getNetworkAddress('255.0.255.255', '255.255.255.240'); // '255.0.255.240/28'
ipv4.getNetworkAddress('23.2.20.23', '240.0.0.0'); // '16.0.0.0/4'
ipv4.getNetworkAddress('255.256.255.255', '255.255.128.0'); // Error: Invalide ip address!
ipv4.getNetworkAddress(255, '255.255.128.0'); // Error: Invalide ip address!
ipv4.getNetworkAddress('255.200.100.10', '255.255.255.250'); // Error: Invalide subnet mask!
ipv4.getNetworkAddress('255.200.100.10', true); // Error: Invalide subnet mask!- Is used in
isNetworkIncludes()method.
Author: Evgheniy Kovaliov <kovaliov.evgeniy11@gmail.com>
For ip version 4
For ip version 6