Posts

Showing posts from January, 2011

Java program to display Local machines IP Address

import java.net.*; import java.io.*; public class iplocalmac {     public static void main(String args[]) throws Exception     {         InetAddress ipadd =InetAddress.getLocalHost();         System.out.println("Host and Address :"+ipadd);         System.out.println("Host name :"+ipadd.getHostName());         String n=ipadd.toString();         System.out.println("IP address :"+n.substring(n.indexOf("/")+1));     } }

Java program to display the IP Address of a particular Host

import java.net.*; import java.io.*; public class iphost {     public static void main(String args[]) throws Exception     {         System.out.println("Enter the host name :");         String n=new DataInputStream(System.in).readLine();         InetAddress ipadd =InetAddress.getByName(n);         System.out.println("IP address :"+ipadd);     } }