Lua获取请求者的ip,浏览器,系统等信息
function getBrowser()
local user_agent = ngx.req.raw_header()
local browser = "others"
if ngx.re.match(user_agent,"Chrome") then
browser = "Chrome"
elseif ngx.re.match(user_agent,"Firefox") then
browser = "Firefox"
elseif ngx.re.match(user_agent,"QQBrowser") then
browser = "QQBrowser"
elseif ngx.re.match(user_agent,"Safari") then
browser = "Safari"
elseif ngx.re.match(user_agent,"Opera") then
browser = "Opera"
elseif ngx.re.match(user_agent,"MSIE 11.0") or ngx.re.match(user_agent,"rv:11.0") then
browser = "IE 11.0"
elseif ngx.re.match(user_agent,"MSIE 10.0") or ngx.re.match(user_agent,"rv:10.0") then
browser = "IE 10.0"
elseif ngx.re.match(user_agent,"MSIE 9.0") or ngx.re.match(user_agent,"rv:9.0") then
browser = "IE 9.0"
elseif ngx.re.match(user_agent,"MSIE 8.0") or ngx.re.match(user_agent,"rv:8.0") then
browser = "IE 8.0"
elseif ngx.re.match(user_agent,"MSIE 7.0") or ngx.re.match(user_agent,"rv:7.0") then
browser = "IE 7.0"
elseif ngx.re.match(user_agent,"MSIE 6.0") or ngx.re.match(user_agent,"rv:6.0") then
browser = "IE 6.0"
else
browser = "others"
end
return browser
end
function getSystem()
local user_agent = ngx.req.raw_header()
local system = "others"
if ngx.re.match(user_agent,"Mac OS") then
system = "Mac OS"
elseif ngx.re.match(user_agent,"Mac") then
system = "Macintosh"
elseif ngx.re.match(user_agent,"Windows NT 10.0") then
system = "Windows 10"
elseif ngx.re.match(user_agent,"Windows NT 6.2") then
system = "Windows 8"
elseif ngx.re.match(user_agent,"Windows NT 6.1") then
system = "Windows 7"
elseif ngx.re.match(user_agent,"Windows NT 6.0") then
system = "Windows Vista"
elseif ngx.re.match(user_agent,"Windows NT 5.1") then
system = "Windows XP"
elseif ngx.re.match(user_agent,"Windows NT 5.0") then
system = "Windows 2000"
elseif ngx.re.match(user_agent,"linux") then
system = "Linux"
elseif ngx.re.match(user_agent,"unix") then
system = "Unix"
elseif ngx.re.match(user_agent,"FreeBSD") then
system = "FreeBSD"
elseif ngx.re.match(user_agent,"IRIX") then
system = "IRIX"
elseif ngx.re.match(user_agent,"OSF1") then
system = "OSF1"
elseif ngx.re.match(user_agent,"BSD") then
system = "BSD"
elseif ngx.re.match(user_agent,"NetBSD") then
system = "NetBSD"
elseif ngx.re.match(user_agent,"HPUX") then
system = "HPUX"
elseif ngx.re.match(user_agent,"AIX") then
system = "AIX"
elseif ngx.re.match(user_agent,"PowerPC") then
system = "PowerPC"
elseif ngx.re.match(user_agent,"sun") then
system = "SUN"
elseif ngx.re.match(user_agent,"ibm") then
system = "IBM"
end
return system
end
function getIP()
return ngx.var.remote_addr
end |