Method to check if a range of IP numbers match the current client ip

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Method to check if a range of IP numbers match the current client ip

Jolle Carlestam-2
It happens that I want to provide access or functionality based on if the visitor comes from a certain IP number. As long as it’s a single IP address or a single IP subnet that is easy in Lasso 9.
client_ip == '127.*’ is perfectly valid and will return true if I access a local install of Lasso.
client_ip == '65.136.211.*’works equally well. Client_ip accepts wildcards when comparing.

But in my case it is often a question of accepting a range of different IP ranges. To help with that I wrote a method called client_ip_isin. It will accept an array, or staticarray, of strings and return true if any of the strings match client_ip.

I’ve put it as a gist found here:
https://gist.github.com/jolle-c/29bb9e8a0dff718de930

Code looks like this:

/**!
client_ip_isin
Will return true if client_ip matches any of the strings in the provided staticarray

Examples
        client_ip_isin((: '127.*', '91.219.213.*'))

2014-09-10 JC First version

*/
define client_ip_isin(check::staticarray) => {

        with item in #check do {
                client_ip == #item ? return true
        }
        return false
}

define client_ip_isin(check::array) => {

        with item in #check do {
                client_ip == #item ? return true
        }
        return false
}

Feel free to use or abuse.

HDB
Jolle

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Method to check if a range of IP numbers match the current client ip

Marc Vos-3
We have a similar check, built-in into our framework. But very little users get this restriction. Practically all are on * - but then, when you need the functionaility, it's there!

We first compare with 'client_address' because we want to be able to use host-names too (IP-address independent). And since using 'client_ip' as an operator had (or still has) its problems, we wrote our own IP-comparison routine.

See for example http://www.lassotalk.com/Msg-Lasso9-take-12-client-ip-and-client-address.lasso?271468
Don't know if it is still actual.

- -
Marc

> On 3 feb. 2016, at 11:32, Jolle Carlestam <[hidden email]> wrote:
>
> It happens that I want to provide access or functionality based on if the visitor comes from a certain IP number. As long as it’s a single IP address or a single IP subnet that is easy in Lasso 9.
> client_ip == '127.*’ is perfectly valid and will return true if I access a local install of Lasso.
> client_ip == '65.136.211.*’works equally well. Client_ip accepts wildcards when comparing.
>
> But in my case it is often a question of accepting a range of different IP ranges. To help with that I wrote a method called client_ip_isin. It will accept an array, or staticarray, of strings and return true if any of the strings match client_ip.
>
> I’ve put it as a gist found here:
> https://gist.github.com/jolle-c/29bb9e8a0dff718de930
>
> Code looks like this:
>
> /**!
> client_ip_isin
> Will return true if client_ip matches any of the strings in the provided staticarray
>
> Examples
> client_ip_isin((: '127.*', '91.219.213.*'))
>
> 2014-09-10 JC First version
>
> */
> define client_ip_isin(check::staticarray) => {
>
> with item in #check do {
> client_ip == #item ? return true
> }
> return false
> }
>
> define client_ip_isin(check::array) => {
>
> with item in #check do {
> client_ip == #item ? return true
> }
> return false
> }
>
> Feel free to use or abuse.
>
> HDB
> Jolle
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>



#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Method to check if a range of IP numbers match the current client ip

Jolle Carlestam-2
I think the client_ip metod is fixed as of March 2013.
http://www.lassosoft.com/rhinotrac?id=7506

This works for me:
client_ip == '::1’
It will, of course return false since the provided client_ip is v 4, not v 6 but it does not throw an error.

It is to the left of my competence profile to work out how to provide Lasso with a v6 IP number.

HDB
Jolle


> 3 feb 2016 kl. 12:52 skrev Marc Vos <[hidden email]>:
>
> We have a similar check, built-in into our framework. But very little users get this restriction. Practically all are on * - but then, when you need the functionaility, it's there!
>
> We first compare with 'client_address' because we want to be able to use host-names too (IP-address independent). And since using 'client_ip' as an operator had (or still has) its problems, we wrote our own IP-comparison routine.
>
> See for example http://www.lassotalk.com/Msg-Lasso9-take-12-client-ip-and-client-address.lasso?271468
> Don't know if it is still actual.
>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>