Lasso Soft Inc. > Home

[client_real_ip]

Linkclient_real_ip
AuthorJohan Solve
CategoryClient
Version8.x
LicensePublic Domain
Posted27 May 2009
Updated27 May 2009
More by this author...

Description

Returns the original client_ip obtained from the request header, instead of the IP of a proxy, firewall, load balancer, performance cache or whatever device that might interact with the traffic between the visitor and the server.

Sample Usage

client_real_ip;

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('client_real_ip',
	-priority='replace');
	// Transform the client request header to a pair array
	local('h'=client_headers -> split('\r\n'),
		'temp'=null,
		'ip'=string);
	iterate(#h, local('r'));
		#temp=#r -> split(':') -> first;
		#r -> removeleading(#temp + ':') & trim;
		#temp = pair(#temp = #r);
		#r=#temp;
	/iterate;
	
	// look for forwarded IP from proxy, firewall or load balancer
	/*	TODO: disregard pripvate IPs, i.e. 10.*, 192.168.* or 172.16.*  172.31.*

		Possible other headers:
		HTTP_PRAGMA, HTTP_XONNECTION, HTTP_CACHE_INFO, HTTP_XPROXY, HTTP_PROXY, HTTP_PROXY_CONNECTION, HTTP_CLIENT_IP, HTTP_VIA, HTTP_X_COMING_FROM, HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED, HTTP_COMING_FROM, HTTP_FORWARDED_FOR, HTTP_FORWARDED, ZHTTP_CACHE_CONTROL
	*/
	if(#h >> 'client-ip');
		#ip = #h -> find('client-ip') -> first -> value;
	else(#h >> 'X-Forwarded-For');
		// de facto standard for proxies, http://en.wikipedia.org/wiki/X-Forwarded-For
		// can also return "unknown"
		#ip = #h -> find('X-Forwarded-For') -> first -> value;
		#ip -> trim;
	else(#h >> 'PC-Remote-Addr');
		// for server side cache, like Performace Cache
		#ip = #h -> find('PC-Remote-Addr') -> first -> value;
	else;
		#ip = string(client_ip);
	/if;
	#ip = #ip -> split(',') -> first; // needed to get the actual client ip for x-forwarded-for, instead of the entire proxy chain
	#ip -> trim;
	return(@#ip);
/define_tag;

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