Merge branch 'hotfix/ipv6' into 'release/5.8'
ipv6 See merge request !662
Showing
1 changed file
with
10 additions
and
1 deletions
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | const _ = require('lodash'); | 8 | const _ = require('lodash'); |
9 | const helpers = global.yoho.helpers; | 9 | const helpers = global.yoho.helpers; |
10 | +const net = require('net'); | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * 获取 IP | 13 | * 获取 IP |
@@ -25,7 +26,15 @@ const _getClientIp = req => { | @@ -25,7 +26,15 @@ const _getClientIp = req => { | ||
25 | remoteIp = req.get('X-Real-IP'); | 26 | remoteIp = req.get('X-Real-IP'); |
26 | } | 27 | } |
27 | 28 | ||
28 | - return _.trim(remoteIp); | 29 | + remoteIp = _.trim(remoteIp); |
30 | + | ||
31 | + if (!net.isIPv4(remoteIp)) { | ||
32 | + let ipv6String = remoteIp.split(':'); | ||
33 | + | ||
34 | + remoteIp = ipv6String[ipv6String.length - 1]; | ||
35 | + } | ||
36 | + | ||
37 | + return remoteIp; | ||
29 | }; | 38 | }; |
30 | 39 | ||
31 | module.exports = () => { | 40 | module.exports = () => { |
-
Please register or login to post a comment