Full width home advertisement

Electronics Hub

Internet of Networks

Post Page Advertisement [Top]

Q. Write a Java Program to implement the ping command. Also check the pinging status of your system


import java.io.*;
import java.net.*;

public class ping
 public static void main (String args[])
  System.out.println("Pinging Status");
  String ipAddress="www.google.com";
    InetAddress inet=InetAddress.getByName(ipAddress);
    System.out.println("Sending the Ping request to "+ipAddress);
    try(Socket socket = new Socket()){
        socket.connect(new InetSocketAddress(ipAddress, 80), 5000);
        System.out.println("Status: Destination host is reachable");
    }catch(Exception ex){
        System.out.println("Status: Destination host is unreachable");
   catch(IOException e)
    System.out.println("Host does not exist");


javac ping.java (//enter)
java ping (//enter)
ping status
Sending ping request to www.google.com
Status: Destination host is reachable
ping meaning, ping definition
Free picture downloaded from unsplash.com

1 comment:

Bottom Ad [Post Page]

| Designed by Sriparna Sarkar