获取客户端信息工具类
import com.wangyao.common.constant.ConstantNumeral;
import jakarta.annotation.Nullable;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
@SuppressWarnings ( "ALL" )
@Slf4j
public class NetworkUtil {
public static final String UNKNOWN = "unknown" ;
public static final String LOCALHOST = "localhost" ;
public static final String STRING = "127.0.0.1" ;
public static final String STRING1 = "0:0:0:0:0:0:0:1" ;
public static final String STR = "," ;
public static final int INT = 15;
@Nullable
public static String getIpAddress ( @NotNull HttpServletRequest request) {
String ip = request.getHeader ( "x-forwarded-for" ) ;
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader ( "Proxy-Client-IP" ) ;
}
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip))