1. Go to this page and download the library: Download rjp2525/laravel-asn library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$matcher = (new IpMatcher)->addPrefix('104.16.0.0/12')->compile();
AsnDns::domainMatchesRanges('cloudflare.com', $matcher); // true
use Reno\ASN\Rules\IpInAsn;
use Reno\ASN\Rules\IpNotInAsn;
use Reno\ASN\Rules\IpInRange;
use Reno\ASN\Rules\DomainInAsn;
// In a FormRequest
public function rules(): array
{
return [
// IP must belong to Cloudflare
'ip' => ['0/16')],
// Domain must resolve to a Cloudflare IP
'domain' => ['
class ServerConfig
{
#[IpInAsn(13335, 15169)]
public string $ip;
#[IpInRange('10.0.0.0/8')]
public string $internalIp;
}
// Filter by CIDR range
User::whereIpInRange('ip_address', '10.0.0.0/8')->get();
// Filter by multiple ranges
User::whereIpInRanges('ip_address', ['10.0.0.0/8', '172.16.0.0/12'])->get();
// Filter by ASN (resolves prefixes automatically)
User::whereIpInAsn('ip_address', 13335)->get();
User::whereIpInAsn('ip_address', [13335, 15169])->get();
// Exclude by ASN
User::whereIpNotInAsn('ip_address', 7922)->get();
// Filter using a pre-compiled matcher
$matcher = Asn::buildMatcher([13335]);
User::whereIpInMatcher('ip_address', $matcher)->get();
// Normalized IP comparison
User::whereIpEquals('ip_address', '8.8.8.8')->get();