js获取客户端ip地址
2018-04-03 本文已影响0人
钱学敏
JS 搜狐接口
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
document.write(returnCitySN["cip"] + ',' + returnCitySN["cname"])
</script>
Node.Js获取
使用request-ip库
npm i request-ip --save
const requestIp = require('request-ip');
const ipMiddleware = function(req, res, next) {
const clientIp = requestIp.getClientIp(req);
next();
};