Enumeration<NetworkInterface> interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
- while (interfaces.hasMoreElements()){
- NetworkInterface current = interfaces.nextElement();
-
- if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue;
- Enumeration<InetAddress> addresses = current.getInetAddresses();
- while (addresses.hasMoreElements()){
- InetAddress current_addr = addresses.nextElement();
- if (current_addr.isLoopbackAddress()) continue;
- if (current_addr instanceof Inet6Address) continue;
-
- loaclIPAddress = current_addr.getHostAddress();
+ if (interfaces != null) {
+ while (interfaces.hasMoreElements()){
+ NetworkInterface current = interfaces.nextElement();
+
+ if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue;
+ Enumeration<InetAddress> addresses = current.getInetAddresses();
+ while (addresses.hasMoreElements()){
+ InetAddress current_addr = addresses.nextElement();
+ if (current_addr.isLoopbackAddress()) continue;
+ if (current_addr instanceof Inet6Address) continue;
+
+ loaclIPAddress = current_addr.getHostAddress();
+ }
}
}
} catch (SocketException e) {