I want to send packets while pinging, like when doing ping on Linux. I know it's possible as I've seen the scripts. I'm having a hard time putting 2 and 2 together.
Basically so it can:
A. Ping the IP
B. Send packets to IP.
So it should look like
Enter IP Address:
1.1.1.1
Sending Ping Request to 1.1.1.1
Host is reachable
Pinging Address
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=4678 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=64 time=3671 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=64 time=2644 ms
64 bytes from 1.1.1.1: icmp_seq=4 ttl=64 time=1624 ms
64 bytes from 1.1.1.1: icmp_seq=5 ttl=64 time=600 ms
64 bytes from 1.1.1.1: icmp_seq=6 ttl=64 time=631 ms
64 bytes from 1.1.1.1: icmp_seq=7 ttl=64 time=452 ms
^C
--- 1.1.1.1 ping statistics ---
10 packets transmitted, 7 received, 30% packet loss, time 9136ms
rtt min/avg/max/mdev = 451.531/2042.841/4678.491/1546.527 ms, pipe 5
Something to that effect.
Current Code:
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class expertping
{
public static void sendPingRequest(String ipAddress)
throws UnknownHostException, IOException
{
InetAddress geek = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
if (geek.isReachable(5000))
System.out.println("Switch is reachable.");
else
System.out.println("Unable to reach Switch.");
}
public static void main(String[] args)
throws UnknownHostException, IOException
{
String ipAddress;
Scanner sc=new Scanner(System.in);
System.out.println("Make sure to type in your switch ipv4, not your PC's.");
System.out.println("Enter IP Address:");
ipAddress=sc.next();
sendPingRequest(ipAddress);
}
}
This thread How to ping an IP address is similar and talks about the problem, but it may/may not talk about how to reintroduce it back into the code.
A person suggest looking here to find my answer for my troubles. The problem is I would like some help attaching to my current code, so it can actually actively connect to it, displaying the packets. My attempts just null out and only do 1 feature.