使用這個庫:request-ip
它按照如下順序獲取請求的IP地址:文章來源:http://www.zghlxwxcb.cn/news/detail-454731.html
- X-Client-IP
- X-Forwarded-For (Header may return multiple IP addresses in the format: “client IP, proxy 1 IP, proxy 2 IP”, so we take the first one.)
- CF-Connecting-IP (Cloudflare)
- Fastly-Client-Ip (Fastly CDN and Firebase hosting header when forwared to a cloud function)
- True-Client-Ip (Akamai and Cloudflare)
- X-Real-IP (Nginx proxy/FastCGI)
- X-Cluster-Client-IP (Rackspace LB, Riverbed Stingray)
- X-Forwarded, Forwarded-For and Forwarded (Variations of #2)
- appengine-user-ip (Google App Engine)
- req.connection.remoteAddress
- req.socket.remoteAddress
- req.connection.socket.remoteAddress
- req.info.remoteAddress
- Cf-Pseudo-IPv4 (Cloudflare fallback)
- request.raw (Fastify)
如果最后都找不到,則返回null。文章來源地址http://www.zghlxwxcb.cn/news/detail-454731.html
到了這里,關(guān)于【JavaScript】如何獲取客戶端IP地址?的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!