Accessing a page if you're within a specific IP address range?

Posted 8 months ago by modiz

I am trying to allow access to a page when someone is within a specific IP range. I am able to do this with a specific ip address but not within a range.

IP middleware

public function handle($request, Closure $next)
        if ($request->ip() != "XXX.XXX.XXX.204"){
        return $next($request);

How do I check if the IP is within a range of Ip?

I want to do something that will filter out the first 3 octets of the ip from the whole IP and check to see if the first 3 octets of the remote IP matches the 3 octets of the IP in the code. Does this makes sense?

For example: Check if the ip has 100.111.23.* -the first 3 octets have to be the same, the * can be any number between 0-255

I dont know how to filter of the first 3 octets of the ip, or check the range in general. Can someone help?

Thanks in advance.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.