This commit is contained in:
Looly 2022-12-05 23:17:46 +08:00
parent b2ce71d9c8
commit e75f4617aa
2 changed files with 9 additions and 2 deletions

View File

@ -743,8 +743,8 @@ public class NetUtil {
*/
public static String getMultistageReverseProxyIp(String ip) {
// 多级反向代理检测
if (ip != null && ip.indexOf(",") > 0) {
final String[] ips = ip.trim().split(",");
if (ip != null && StrUtil.indexOf(ip, ',') > 0) {
final List<String> ips = StrUtil.splitTrim(ip, ',');
for (final String subIp : ips) {
if (false == isUnknown(subIp)) {
ip = subIp;

View File

@ -112,4 +112,11 @@ public class NetUtilTest {
Assert.assertFalse(NetUtil.isInRange("114.114.114.114","192.168.3.4/32"));
}
@Test
public void issueI64P9JTest() {
// 获取结果应该去掉空格
final String ips = "unknown, 12.34.56.78, 23.45.67.89";
final String ip = NetUtil.getMultistageReverseProxyIp(ips);
Assert.assertEquals("12.34.56.78", ip);
}
}