You are on page 1of 1

//945-89832956 http://www.ozekisms.com/index.php?ow_page_number=206 import import import import import import java.net.InetAddress; java.net.NetworkInterface; java.net.SocketException; java.net.UnknownHostException; java.util.Collections; java.util.

Enumeration;

/** * Program to display current computer name, IP Address and network interfaces * * @author sahir maredia (Kotia Solutions) * */ public class ComputerName { /** * @param args */ public static void main(String[] args) { try { InetAddress ipaddress = InetAddress.getLocalHost(); System.out.println("Computer Host Name : " + ipaddress.getHostName()); System.out.println("IP Address of Localhost : " + ipaddress.getHostAddress()); // getting list of network interfaces Enumeration<NetworkInterface> interfaces = NetworkInterface .getNetworkInterfaces(); System.out.println(); System.out .println("================ Following are the available network interfaces == ============="); System.out.println(); if (interfaces == null) { System.out.println("No network interfaces found"); } else { for (NetworkInterface netIf : Collections.list(interfaces)) { System.out.println("Display Name : " + netIf.getDisplayName()); System.out.println("Name : " + netIf.getName()); System.out.println(); } } } catch (UnknownHostException ex) { System.out.println("Error Occured : " + ex.getMessage()); } catch (SocketException e) { System.out.println("Error Occured : " + e.getMessage()); } } }

You might also like