星空网 > 软件开发 > Java

Node.js、Express框架获取客户端IP地址

Node.js

//传入请求HttpRequestfunction getClientIp(req) {    return req.headers['x-forwarded-for'] ||    req.connection.remoteAddress ||    req.socket.remoteAddress ||    req.connection.socket.remoteAddress;}

 

Express

//express框架则简单许多req.ip

 

意外收获

          发现这两种方式获取的ip地址都带有前缀,不知为何,看了眼Express request.js源码,没找到不对的地方。所以用正则表达式处理了下

req.ip.match(/\d+\.\d+\.\d+\.\d+/)

 




原标题:Node.js、Express框架获取客户端IP地址

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

美姑专线物流:https://www.goluckyvip.com/tag/37929.html
美股资讯:https://www.goluckyvip.com/tag/37930.html
美国 fba 费用:https://www.goluckyvip.com/tag/37931.html
美国 fba 敏感货:https://www.goluckyvip.com/tag/37932.html
美国 fba 头程:https://www.goluckyvip.com/tag/37933.html
美国&加拿大劳动节:https://www.goluckyvip.com/tag/37934.html
蓝色港湾地址及周边景点介绍(让你轻松玩转这个美丽的海滨城市):https://www.vstour.cn/a/362185.html
宁夏室内景点大全 宁夏旅游景点有哪些:https://www.vstour.cn/a/362186.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流