[Banned_IP]

Description

Link: [Banned_IP]
Author: Israel Thompson
Category: Session
Version: 8.5.x
License: Public Domain
Posted: Jan. 08, 2009
Updated: Jan. 08, 2009
More by this author...

Use this tag to quickly compare a list of banned IP addresses, IP Ranges, or IP Subnets to a user's [Client_IP]. The tag which is named "Banned_IP" appropriately reports either TRUE if the user is in your banned list or FALSE if they are not.

This tag is intended to aid site administrators in denying or allowing users login privileges, session capabilities, blog/forum posting, and much more.

Technical Details:

Whether you're storing your banned IP's, ranges, or subnets in a database table or elsewhere the tag looks for a single array named "banned_ipv4" which contains them all.

Formatting of your items should be as follows.

IP Address: 192.168.1.1
IP Range: 192.168.1.1/25
IP Subnet: 192.168.1

When invoking the tag make sure the [$banned_ipv4] variable exists. Sample usage is as follows:

var('banned_ipv4' = (:'192.168.1.1', '192.168.1.1/25', '192.168.1'));

banned_ip;

Testing:

To test the tag, find out your own [Client_IP] by going to a site like http://whatismyip.org/. Once you've got your own IP address you can type it into the [$banned_ipv4] array and the tag should output TRUE.

Feel free to drop me a line if you need any help or see anything that needs improvement.

Parameters

none


Sample Usage

Sample usage is as follows:

var('banned_ipv4' = (:'192.168.1.1', '192.168.1.1/25', '192.168.1'));

banned_ip;

Testing:

To test the tag, find out your own [Client_IP]
by going to a site like http://whatismyip.org/.
Once you've got your own IP address you can 
type it into the [$banned_ipv4] array and the 
tag should output TRUE.

Feel free to drop me a line if you need any 
help or see anything that needs improvement.
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
define_tag('banned_ip', -optional='evaluate');
	local('evaluate' = var('banned_ipv4'), 'user_ip' = string(client_ip), 'banned' = FALSE, 'end_loop' = FALSE);
	if(#evaluate->size > 0);
		while(#banned == FALSE && #end_loop == FALSE);
			local('item' = #evaluate->get(loop_count));
			if(#item != NULL);
				//evaluate banned subnets
				if(#item->split('.')->size == 3 && #item->split('.')->last !>> '/');
					if(#user_ip >> #item);
						#banned = TRUE;
					/If;
				/if;
				//evaluate banned ranges
				if(#item->split('.')->size == 4 && #item->split('.')->last >> '/' && #banned == FALSE);
					local('range' = #item,
						'range_octets' = #range->split('.'),
						'range_subnet' = #range_octets->get(1) + '.' + #range_octets->get(2) + '.' + #range_octets->get(3),
						'range_octet4' = #range_octets->get(4),
						'range_start' = integer(#range_octet4->split('/')->first),
						'range_end' = integer(#range_octet4->split('/')->last),
						'user_ip_octets' = #user_ip->split('.'),
						'user_ip_subnet' = #user_ip_octets->get(1) + '.' + #user_ip_octets->get(2) + '.' + #user_ip_octets->get(3),
						'user_ip_octet4' = integer(#user_ip_octets->get(4)));
					if(#range_subnet == #user_ip_subnet);
						if(#user_ip_octet4 >= #range_start && #user_ip_octet4 <= #range_end);
							#banned = TRUE;
						/if;			
					/if;
				/if;
				//evaluate banned IP's
				if(#item->split('.')->size == 4 && #item->split('.')->last !>> '/' && #banned == FALSE);
					if(#item >> #user_ip);
						#banned = TRUE;
					/if;
				/if;
			/if;
			loop_count == #evaluate->size ? #end_loop = TRUE;
		/while;
	/if;
	return(#banned);
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net