Skip to content

Commit e7af9e7

Browse files
committed
Add Client address to request data .
1 parent c769881 commit e7af9e7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

server/src/main/java/com/androthink/server/helper/NetworkHelper.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,17 @@ public static String getIPAddress(boolean useIPv4) throws SocketException{
5151
List<InetAddress> addressList = Collections.list(netInterface.getInetAddresses());
5252
for (InetAddress address : addressList) {
5353
if (!address.isLoopbackAddress()) {
54-
return getIp(address,useIPv4);
54+
String addressString = address.getHostAddress();
55+
boolean isIPv4 = addressString.indexOf(':') < 0;
56+
if (useIPv4) {
57+
if (isIPv4)
58+
return addressString;
59+
} else {
60+
if (!isIPv4) {
61+
int delim = addressString.indexOf('%'); // drop ip6 zone suffix
62+
return delim < 0 ? addressString.toUpperCase() : addressString.substring(0, delim).toUpperCase();
63+
}
64+
}
5565
}
5666
}
5767
}

0 commit comments

Comments
 (0)