0

I don't know how to access header fields of a packet and how to generate ICMP and IP packet in java.

  InetAddress ia = InetAddress.getLocalHost();
  int port = 7;

  DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); 

Is this a right way or I am going in wrong direction?

Vikram
  • 3,996
  • 8
  • 37
  • 58
Nisarg
  • 367
  • 1
  • 6
  • possible duplicate of [java code to ping an IP address](http://stackoverflow.com/questions/11506321/java-code-to-ping-an-ip-address) – DavidPostill Aug 28 '14 at 21:05

1 Answers1

0

Wrong direction. It is not possible to send ICMP packets in pure Java.

It would require to implement it in another language like C and call it via JNI.

icza
  • 389,944
  • 63
  • 907
  • 827