Feb 03
Jolle Carlestam Method to check if a range of IP numbers match the current client ip
Feb 03, 2016; 11:32
Jolle Carlestam
Method to check if a range of IP numbers match the current client ip
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 Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Feb 03
Marc Vos Re: Method to check if a range of IP numbers match the current client ip
Feb 03, 2016; 12:52
Marc Vos
Re: Method to check if a range of IP numbers match the current client ip
Feb 03
Jolle Carlestam Re: Method to check if a range of IP numbers match the current client ip
Feb 03, 2016; 13:29
Jolle Carlestam
Re: Method to check if a range of IP numbers match the current client ip