1

I want to implement traceroute/ping/dns lookup in the my application. For ping i use a ProcessBuilder:

    ProcessBuilder processBuilder = new ProcessBuilder("ping", "-c 1", host);
    Process process = processBuilder.start();

But how can i use a traceroute and dns lookup? Is it possible without root? Thx.

Yuriy Aizenberg
  • 373
  • 9
  • 28

1 Answers1

0

Regarding the traceroute command. This command is essentially recursive ping with TTL (time to live) flag set. TTL does not have anything to do with time. Instead it's a hop counter. Each time the IP packet passes through a router or switch the TTL field is decremented by 1. This field is 8 bits long, so max hops would be 255.

This means that you can do your own traceroute with ping.

Something like:

ProcessBuilder processBuilder;
for(int i = 100; i != 0; i--) {
  processBuilder = new ProcessBuilder("ping", "-c 1 -T " + i, host);
  /* do stuff here */
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Ben
  • 3,012
  • 1
  • 21
  • 25