package com.framework.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.hutool.http.HttpUtil;
public class GetIp {
public static String getIp() {
String result = "127.0.0.1";
try {
String json = HttpUtil.get("http://pv.sohu.com/cityjson");
String regEx = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(json);
while (m.find()) {
result = m.group();
}
} catch (Exception e) {
e.printStackTrace();
result = "127.0.0.1";
}
return result;
}
}
获取本机外网IP
最新推荐文章于 2024-08-20 12:11:56 发布