public class IpUtil extends Object
| 构造器和说明 |
|---|
IpUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
getIpAddr()
获取客户端IP地址
|
static String |
getIpAddrAndName()
获取客户端IP地址
|
static String |
getMacAddress(String ip)
获得MAC地址
|
static String |
getPoxyIp(javax.servlet.http.HttpServletRequest request)
获取有网关是 的真正客户端IP 测试过nginx可以获取
location /test/ {
proxy_pass http://localhost:9002/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
|
static String |
getPoxyIpEnhance(javax.servlet.http.HttpServletRequest request)
增强版 - 普通使用getPoxyIp即可满足需求
获取有网关是 的真正客户端IP 测试过nginx可以获取
|
static String |
getRealIp()
获取本地真正的IP地址,即获得有线或者无线WiFi地址。
|
static String |
ipConvert(String domainName)
ip转换
|
public static String getPoxyIp(javax.servlet.http.HttpServletRequest request)
location /test/ {
proxy_pass http://localhost:9002/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
public static String getPoxyIpEnhance(javax.servlet.http.HttpServletRequest request)
public static String getRealIp() throws SocketException
SocketExceptionpublic static String getMacAddress(String ip)
public static String getIpAddrAndName() throws IOException
IOExceptionpublic static String getIpAddr() throws IOException
IOExceptionCopyright © 2021 tan. All rights reserved.