PHPackages                             miken32/network-rules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. miken32/network-rules

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

miken32/network-rules
=====================

Laravel validation rules for checking IP addresses and networks

v2.2(3mo ago)1251.2k↑86.1%3AGPL-3.0PHPPHP ^8.1

Since Oct 17Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/miken32/NetworkRules)[ Packagist](https://packagist.org/packages/miken32/network-rules)[ RSS](/packages/miken32-network-rules/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (7)Versions (8)Used By (0)

A Collection of Rules
for the *Reliable Validation*
of
Internet Protocol Addreſſes,
Networks, and Subnets
*which the author hopes will be found uſeful to*
***Laravel Programmers** &amp;c.*

Installation
------------

[](#installation)

```
composer require miken32/network-rules
```

Available Validation Rules
--------------------------

[](#available-validation-rules)

Here is a list of the available rules and their usage.

[In Network](#in_networkcidr)
[Outside Network](#outside_networkcidr)
[IP Or Net](#ip_or_net)
[Network](#network)
[Netv4](#netv4lowhigh)
[Netv6](#netv6lowhigh)
[Private IP](#private_ip)
[Private IPv4](#private_ipv4)
[Private IPv6](#private_ipv6)
[Private Net](#private_net)
[Routable IP or Net](#routable_ip_or_net)
[Routable IP](#routable_ip)
[Routable IPv4](#routable_ipv4)
[Routable IPv6](#routable_ipv6)
[Routable Net](#routable_netlowhigh)
[Routable Netv4](#routable_netv4lowhigh)
[Routable Netv6](#routable_netv6lowhigh)

### in\_network:*cidr*,...

[](#in_networkcidr)

The field under validation must be an IP address within one of the given networks. The networks must be given in CIDR notation, and may be either IPv4 or IPv6 networks.

```
'ip4_address' => 'in_network:192.168.0.1/24',
'some_address' => 'in_network:192.168.0.0/24,192.168.1.0/24,192.168.2.0/24',
'ip6_address' => 'in_network:fd03:224f:a5c3:99ae::0/64'

```

### outside\_network:*cidr*,...

[](#outside_networkcidr)

The field under validation must be an IP address outside all of the given networks. The networks must be given in CIDR notation, and may be either IPv4 or IPv6 networks.

```
'ip4_address' => 'outside_network:192.168.0.1/24',
'some_address' => 'outside_network:192.168.0.0/24,192.168.1.0/24,192.168.2.0/24',
'ip6_address' => 'outside_network:fd03:224f:a5c3:99ae::0/64'

```

### ip\_or\_net

[](#ip_or_net)

The field under validation must be an IP address or network in CIDR notation. The address or network may be either IPv4 or IPv6.

### network

[](#network)

The field under validation must be an IP network in CIDR notation. The network may be either IPv4 or IPv6; use individual rules to limit mask bits.

### netv4:*low*,*high*

[](#netv4lowhigh)

The field under validation must be an IPv4 network in CIDR notation. If provided, the number of bits in the mask must be between `low` and `high`.

```
'bounded_network'   => 'netv4:20,24',
'unbounded_network' => 'netv4'

```

### netv6:*low*,*high*

[](#netv6lowhigh)

The field under validation must be an IPv6 network in CIDR notation. If provided, the number of bits in the mask must be between `low` and `high`.

```
'bounded_network'   => 'netv6:56,64'
'unbounded_network' => 'netv6'

```

### private\_ip

[](#private_ip)

The field under validation must be a private IPv4 or IPv6 address. Private addresses are defined as being within one of the following networks:

- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
- fc00::/7

The following networks are considered *reserved*, not *private*. They are **not** considered valid by this rule:

- 0.0.0.0/8
- 127.0.0.0/8
- 169.254.0.0/16
- 240.0.0.0/4
- ::/128
- ::1/128
- 2001:10::/28
- 2001:db8::/32
- 3ffe::/16
- 5f00::/8
- fe80::/10

### private\_ipv4

[](#private_ipv4)

The field under validation must be a private IPv4 addresses. The networks considered private are described in the `private_ip` rule.

### private\_ipv6

[](#private_ipv6)

The field under validation must be a private IPv6 addresses. The networks considered private are described in the `private_ip` rule.

### private\_net

[](#private_net)

The field under validation must be a private IP network in CIDR notation. The networks considered private are described in the `private_ip` rule.

### routable\_ip\_or\_net

[](#routable_ip_or_net)

The field under validation must be a globally routable IP address or network in CIDR notation. This excludes all private and reserved ranges, as detailed the the `private_ip` rule.

### routable\_ip

[](#routable_ip)

The field under validation must be a globally routable IPv4 or IPv6 address. This excludes all private and reserved ranges, as detailed the the `private_ip` rule.

### routable\_ipv4

[](#routable_ipv4)

The field under validation must be a globally routable IPv4 address. This excludes all private and reserved ranges, as detailed the the `private_ip` rule.

### routable\_ipv6

[](#routable_ipv6)

The field under validation must be a globally routable IPv6 address. This excludes all private and reserved ranges, as detailed the the `private_ip` rule.

### routable\_net:*low*,*high*

[](#routable_netlowhigh)

The field under validation must be a globally routable IP network in CIDR notation. The network must not overlap any private or reserved ranges, as detailed the the `private_ip` rule. If provided, the number of bits in the mask must be between `low` and `high`.

### routable\_netv4:*low*,*high*

[](#routable_netv4lowhigh)

The field under validation must be a globally routable IPv4 network in CIDR notation. The network must not overlap any private or reserved ranges, as detailed the the `private_ip` rule. If provided, the number of bits in the mask must be between `low` and `high`.

### routable\_netv6:*low*,*high*

[](#routable_netv6lowhigh)

The field under validation must be a globally routable IPv6 network in CIDR notation. The network must not overlap any private or reserved ranges, as detailed the the `private_ip` rule. If provided, the number of bits in the mask must be between `low` and `high`.

Usage
-----

[](#usage)

The included validation rules can be used either as traditional string-based validation rules or as instantiated classes. The following code blocks perform identical validations.

```
