# How to conditionally "if" match a network range?

**URL:** <https://www.ruby-forum.com/t/how-to-conditionally-if-match-a-network-range/190333>\
**Category:** NGINX\
**Created:** [June 17, 2010, 9:18pm UTC](https://www.ruby-forum.com/t/how-to-conditionally-if-match-a-network-range/190333 "2010-06-17T21:18:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_DJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/73ab20/32.png) [@Ben\_DJ](https://www.ruby-forum.com/u/Ben_DJ)\
**Post date:** [June 17, 2010, 9:18pm UTC](https://www.ruby-forum.com/t/how-to-conditionally-if-match-a-network-range/190333/1 "2010-06-17T21:18:51Z")

</div>

hi,

this works fine,

if ($remote\_addr = 1.2.3.4) {  
…  
}

i’d like to match, rather than on a single IP, to a network range. in  
effect,

if ($remote\_addr = 1.2.3.0/24) {  
…  
}

but, afaict, that doesn’t work.

is there a way to conditionally match $remote\_addr against a network  
range?

thanks,

bendj

---

<div class="post-metadata">

**Author:** ![Ben\_DJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/73ab20/32.png) [@Ben\_DJ](https://www.ruby-forum.com/u/Ben_DJ)\
**Post date:** [June 17, 2010, 9:37pm UTC](https://www.ruby-forum.com/t/how-to-conditionally-if-match-a-network-range/190333/2 "2010-06-17T21:37:01Z")

</div>

Today Jun 17, 2010 at 12:17 Ben DJ wrote:

> i’d like to match, rather than on a single IP, to a network range. in effect,
> 
> if ($remote\_addr = 1.2.3.0/24) {  
> …  
> }
> 
> but, afaict, that doesn’t work.

[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpGeoModule)

geo $mysubnet {  
default 0;  
1.2.3.0/24 1;  
}  
…  
if ($mysubnet) {  
…  
}

–  
WNGS-RIPE

---

<div class="post-metadata">

**Author:** ![Ben\_DJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/73ab20/32.png) [@Ben\_DJ](https://www.ruby-forum.com/u/Ben_DJ)\
**Post date:** [June 17, 2010, 9:41pm UTC](https://www.ruby-forum.com/t/how-to-conditionally-if-match-a-network-range/190333/3 "2010-06-17T21:41:07Z")

</div>

On Thu, Jun 17, 2010 at 12:36 PM, Oleksandr V. Typlyns’kyi  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpGeoModule)

Perfect! Looking in the wrong place – again …

Thanks!

BenDJ
