# ipv4

Extension for asserting IPv4 addresses

## isInSubnet

Returns true is the supplied IP belongs to the supplied subnet in CIDR notation.

Use this function to assert that a client belongs to a specific network.

IP-addresses should be octets in dotted-string format: `'192.168.30.5'`

Subnets are specified using CIDR notation containing an ip and the length of the subnet mask: `'10.1.1.0/24'`

### Syntax

`ipv4.isInSubnet(ip, subnet)`

### Arguments

<table><thead><tr><th width="160">Name</th><th width="181">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>ip</code></td><td><code>string</code></td><td>The IP-address in octets</td></tr><tr><td><code>subnet</code></td><td><code>string</code></td><td>The subnet in CIDR-notation</td></tr></tbody></table>

### Example

```
ipv4.isInSubnet('127.0.0.1', '127.0.0.0/8') // true

ipv4.isInSubnet('192.168.10.25', '192.168.10.0/24') // true
ipv4.isInSubnet('192.168.10.25', '192.168.0.0/16') // true

ipv4.isInSubnet('192.168.10.25', '10.0.1.0/24') // false
ipv4.isInSubnet('192.168.10.25', '192.168.11.0/24') // false
```

