public
static
void main(String[] args) {
try
{
Enumeration<NetworkInterface> enumeration = NetworkInterface
.getNetworkInterfaces();
while
(enumeration.hasMoreElements()) {
NetworkInterface networkInterface = enumeration.nextElement();
if
(networkInterface.isUp()) {
Enumeration<InetAddress> addressEnumeration = networkInterface
.getInetAddresses();
while
(addressEnumeration.hasMoreElements()) {
String ip = addressEnumeration.nextElement()
.getHostAddress();
final
String REGX_IP =
"((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)"
;
if
(ip.matches(REGX_IP) && !ip.equals(
"127.0.0.1"
)) {
System.out.println(ip);
}
}
}
}
}
catch
(Exception e) {
log.error(
"获取本机ip出现异常,异常信息为:"
+ e.getMessage());
}
}