Lasso Soft Inc. > Home

[Banned_IP]

LinkBanned_IP
AuthorIsrael Thompson
CategorySession
Version8.5.x
LicensePublic Domain
Posted08 Jan 2009
Updated08 Jan 2009
More by this author...

Description

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.

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.

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

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft