Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getIpAddress() {
- try {
- for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en
- .hasMoreElements();) {
- NetworkInterface intf = (NetworkInterface) en.nextElement();
- for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr
- .hasMoreElements();) {
- InetAddress inetAddress = (InetAddress) enumIpAddr
- .nextElement();
- if (!inetAddress.isLoopbackAddress()
- && inetAddress instanceof Inet4Address) {
- String ipAddress = inetAddress.getHostAddress()
- .toString();
- System.out.println("IP address: " + ipAddress);
- return ipAddress;
- }
- }
- }
- } catch (Exception ex) {
- System.out
- .println("Socket exception in GetIP Address of Utilities");
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment