[luci] To Get Client IP Addr - Problem solved.

Patrick Sun lawipac at gmail.com
Thu Jan 14 14:18:09 CET 2010


Hi Jow, 


> Try to obtain the client addr with:
> 
> local addr = luci.http.getenv("REMOTE_ADDR") .. ":" ..
>     luci.http.getenv("REMOTE_PORT")
> 



    The high level abstraction you mentioned in last email give me a
nice guide... 

    I seached available apis. and I found luci.sys.getenv() is the
function to call. it returns a table with everything environment
variables.

    Below is the function I manage to print the environment variables
including REMOTE_ADDR



function action_tryme()
    local env = luci.sys.getenv();
    luci.http.prepare_content("text/plain")
    luci.http.write("<br> some text floows\n" .. type(env) .. "\n" );
    for i, v in pairs (env) do 
	luci.http.write( i );
	luci.http.write( "\t" );
	luci.http.write( v );
	luci.http.write( "\n" );
    end
end

-- the result is  -----

<br> some text floows

table
HTTP_ACCEPT	text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
CONFIG_cfg024e53_TYPE	httpd
CONFIG_NUM_SECTIONS	1
OLDPWD	/usr/lib/lua/luci/controller
HOME	/root
CONFIG_cfg02f02f_TYPE	system
GATEWAY_INTERFACE	CGI/1.1
CONFIG_SECTIONS	cfg024e53
home	/www
CONFIG_cfg04315a_TYPE	button
SCRIPT_FILENAME	/www/cgi-bin/l
REQUEST_URI	/cgi-bin/l/;stok=5F2D3D9DB012B9E7010D83A105CB7E9A/mini/index/index/
c_file	
CONFIG_cfg0638e0_TYPE	button
CONFIG_cfg04315a_button	reset
CONFIG_cfg0638e0_button	reset
CONFIG_cfg024e53_port	80
CONFIG_cfg04315a_handler	logger reboot
CONFIG_cfg0638e0_max	30
HTTP_ACCEPT_LANGUAGE	en-us,zh-cn;q=0.7,zh;q=0.3
CONFIG_cfg0638e0_min	5
CONFIG_cfg024e53_home	/www
PS1	\u@\h:\w\$ 
HTTP_USER_AGENT	Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7
CONFIG_SECTION	cfg024e53
CONFIG_cfg0638e0_handler	logger factory default
SCRIPT_NAME	/cgi-bin/l
TERM	vt102
PWD	/usr/lib/lua/luci
HTTP_REFERER	http://192.168.1.1/cgi-bin/l/;stok=5F2D3D9DB012B9E7010D83A105CB7E9A/mini/index/index/
CONFIG_cfg04315a_min	0
port	80
CONTENT_TYPE	application/x-www-form-urlencoded
hostname	OpenWrt
CONFIG_cfg04315a_max	4
HTTP_COOKIE	sysauth=F3B71757B1DC213EB84FBD40C34E7082
CONTENT_LENGTH	23
realm	OpenWrt
REMOTE_PORT	53904
SHELL	/bin/sh
REMOTE_ADDR	192.168.1.2
CONFIG_cfg02f02f_hostname	OpenWrt
SERVER_PROTOCOL	HTTP/1.0
PATH	/bin:/sbin:/usr/bin:/usr/sbin
QUERY_STRING	
SERVER_SOFTWARE	busybox httpd/1.11.2
USER	root
PATH_INFO	/;stok=5F2D3D9DB012B9E7010D83A105CB7E9A/mini/index/index/
cfgtype	httpd
args	-p 80 -h "/www" -r "OpenWrt"
CONFIG_cfg04315a_action	released
CONFIG_cfg0638e0_action	released
CONFIG_cfg02f02f_timezone	UTC
REQUEST_METHOD	POST

--------------

cheers
Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.subsignal.org/pipermail/luci/attachments/20100115/5e9c77cd/attachment-0001.htm 


More information about the luci mailing list