Anda di halaman 1dari 3

EXPERIMENT - 5

Aim :- Program to implement ICMP.

NAME :- Nirav Davra

BRANCH :- CS

ROLL NO :- 374

DATE :- 25/03/2011

SUBJECT :- Advanced Computer Networks.

Sign:-____________ Grade:-_____________
JAVA-CODE:-
import javax.swing.*;

import java.net.InetAddress;

public class ICMP{

public static void main(String args[]){

try {

UIManager.setLookAndFeel(UIManager. getSystemLookAndFeelClassName
() );}

catch ( Exception e ) {}

int time = 0;

while(true) {

time = Integer.parseInt( JOptionPane.showInputDialog ( "Enter The


Time" ));

break;}

time *=1000;

String str = JOptionPane.showInputDialog( "Enter the host" );

try

{ InetAddress address = InetAddress.getByName(str);

// Try to reach the specified address within the timeout

// periode. If during this periode the address cannot be

// reach then the method returns false.

boolean reachable = address.isReachable(time);

if(reachable)

{ JOptionPane.showMessageDialog( null,str+"Host is
connected","Alert", JOptionPane.ERROR_MESSAGE); }

else
{ JOptionPane.showMessageDialog( null,str+"Host is
not connected","Alert", JOptionPane.ERROR_MESSAGE);
}

System.out.println("Is host reachable? " + reachable);

} catch (Exception e)

{ e.printStackTrace();

} }}

Output:-

Anda mungkin juga menyukai