File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Someone please help me with the traceroute using jpcap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Someone please help me with the traceroute using jpcap" Watch "Someone please help me with the traceroute using jpcap" New topic
Author

Someone please help me with the traceroute using jpcap

rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Hi,

I was trying to create a traceroute program using jpcap.
There was an example prrovided by the jpcap developer but it doesn't works.
Anyone ever try this before?perhaps i missed something. cause when i run the program,
it gave me this output only: Usage: java Traceroute <device index (e.g., 0, 1..)> <target host address>

this is the example:




Anyone successfully use this example?
can you please help me?
Thanks..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
If you look at the first few lines of the main method, you'll see that this message is printed if you don't supply two command line parameters. It's trying to tell you what those parameters should be. So: what, exactly, did you enter on the command line?


Ping & DNS - my free Android networking tools app
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
I don't enter the two command lines.
To be honest, I don't know where to enter that two command lines.
Can you please help?

Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
The target host address is the IP address of the machine to which you want to find the route.

The device index is a bit trickier, there's some explanation at http://netresearch.ics.uci.edu/kfujii/jpcap/doc/tutorial/, especially the section on "Obtain the list of network interfaces".
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Thanks for your explanation, I got it.
I'll give it a try
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
hi Dittmer,

I've tried that but it gave me exception error.

Exception in thread "main" java.lang.NoClassDefFoundError: Traceroute/java

any idea?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
What, exactly, did you enter on the command line? It should be something like "java Traceroute 0 87.248.122.122".
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

rosy Jovita wrote:hi Dittmer,

I've tried that but it gave me exception error.

Exception in thread "main" java.lang.NoClassDefFoundError: Traceroute/java

any idea?

Ulf is right. You tried to execute Traceroute.java, but you mustn't type in the source file but the class name.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
I have tried to run this program again using this : java Traceroute 0 10.87.224.78
Still,it gave me exception error.
please someone help me with this..
I have tried many times but it doesn't work.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
it gave me exception error.

We do not have access to your screen, so we don't know what error that is; that makes it exceedingly difficult to help.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

rosy Jovita wrote:I have tried to run this program again using this : java Traceroute 0 10.87.224.78
Still,it gave me exception error.
please someone help me with this..
I have tried many times but it doesn't work.


for me it gave arrayIndexOutofBoundsException

because the line


maybe for you as well as me, device list is empty because of privilege issue (java code run by ordinary user cannot get list of devices)

so I add this to code:


Once I ran as administrator, it worked for me.

rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
hi,

okay, first of all i'm having problem with ping.
I'm not sure if this problem affected the Traceroute.
I tried to ping www.google.com to get the ip address but the result turned to be
like this:

C:\Documents and Settings\ros>ping www.google.com
'ping' is not recognized as an internal or external command,
operable program or batch file.

And then, I tried the traceroute again, this is what i get:

C:\Documents and Settings\ros>java Traceroute 0 10.201.54.87
Exception in thread "main" java.lang.NoClassDefFoundError: Traceroute

Does the ping problem affect the traceroute?If yes, then i think it is my pc problem.
For your information, i am using my personal notebook and i am the admin.

Thanks..again,i'm looking forward for replies.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
While ping uses similar mechanism underneath, the fact that it doesn't run as an executable doesn't impact whether or not other similar tools can run. Does your installation actually have a version of ping installed? Check the PATH for "ping.exe", and consult the Windows documentation about it.

Is the file Traceroute.class in the C:\Documents and Settings\ros directory? If so, you may have a CLASSPATH setting that doesn't include the current directory ("."). I generally advise not to use CLASSPATh at all - it's more trouble than it's worth. In that case, you can run the code via "java -classpath . Traceroute 0 10.201.54.87".
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
hi ulf,

Yes, The Traceroute.class is in the C:\Documents and Settings\ros directory.
Okay, let me give it a try. Thanks Ulf.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Hi tim and ulf,

I've fixed the problem, i didn't include the jpcap.dll in the jre library.
But now i'm having problem with getting the MAC address of the default gateway.

run the code and got this output:


C:\Documents and Settings\ros\Desktop>java Traceroute 0 216.239.61.104
devices: 3
cannot obtain MAC address of default gateway.

Anything else i missed out?
Thanks for help


Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

rosy Jovita wrote:Hi tim and ulf,

I've fixed the problem, i didn't include the jpcap.dll in the jre library.
But now i'm having problem with getting the MAC address of the default gateway.

run the code and got this output:


C:\Documents and Settings\ros\Desktop>java Traceroute 0 216.239.61.104
devices: 3
cannot obtain MAC address of default gateway.

Anything else i missed out?
Thanks for help


I had the same problem until I listed out the devices.
for me, the first device in the list (which you get by using "0") didn't work. Try java Traceroute 1 216.239.61.104
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Tim,

will you mind to post the sample output that you get?
Thanks.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

rosy Jovita wrote:Tim,

will you mind to post the sample output that you get?
Thanks.


here is the result at work, including the listing of devices (this router is not reporting on what happens beyond and so my traceroute only shows the steps from my PC to the router).
I'll post what I get from my home network later if you'd like
C:\java>java Traceroute 1 google.com
\Device\NPF_GenericDialupAdapter : Adapter for generic dialup and VPN capture
\Device\NPF_{0D558F01-DFD8-4270-89D9-3676F7620BD7} : Intel(R) 82567LM Gigabit Network Connection
\Device\NPF_{1BAA617E-8926-4C98-B0EE-8F3794197CF6} : Juniper Network Connect Virtual Adapter
\Device\NPF_{4BBD00CF-08F5-427F-BEC5-5A1DD41CE5C0} : VMware Virtual Ethernet Adapter
\Device\NPF_{63B2F25F-D0EE-4F8F-BFD3-3C7B732059F7} : VMware Virtual Ethernet Adapter
0: 10.20.252.162/10.20.252.162
1: 10.20.252.162/10.20.252.162

compare this to the tracert.exe command from DOS. That gives me 16 hops from me to google.com
I don't yet know how to fix traceroute.java to show the 16 hops.


Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I added the following


right before the first



and I see now that this program we are using, Traceroute.java sends this icmp packet out with a hop_limit of ZERO. This value is decreased by one every time it goes through a router and if the
router sees zero, it throws the packet away So, we can't expect it to go anywhere. It is supposed to be increased by 1 in the if... else tree, but this branch of code is never reached.

So, this program is flawed in so many ways.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

So, I ran it again, printing out the TYPE of the returning packet (p)
here is a chart of all the constant values

http://netresearch.ics.uci.edu/kfujii/jpcap/doc/javadoc/constant-values.html
and I see that while it is finding the ICMP_TIMXCEED branch of the code on the first hop, and correctly adding 1 to the hop_limit,

the next time, it recieves a 3, which by the chart is ICMP_REDIRECT_TOSHOST and is not handled by the if...then...else


Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

so, I added



and now I'm getting something that resembles my tracert output.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Tim,

Thanks a lot for the sample output and for the help.
Thank you very much. I've compare with mine.
I get the same output, only that i don't display each of the network device.
This is mine:



Yeah, i was thinking of that too. I'll try it soon.
Thanks for your help, thank you very much
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45


here is the result at work, including the listing of devices (this router is not reporting on what happens beyond and so my traceroute only shows the steps from my PC to the router).
I'll post what I get from my home network later if you'd like



Thanks Tim, i'll wait for the sample output from your home network.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45


here is the result at work, including the listing of devices (this router is not reporting on what happens beyond and so my traceroute only shows the steps from my PC to the router).
I'll post what I get from my home network later if you'd like



Thanks Tim, i'll wait for the sample output from your home network.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Hi all,

anybody can tell me what's the function of these two?

icmp.seq=100;
icmp.id=0;

i have no idea on how does it works, sorry..i'm still new to java networking.
thanks for help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Wikipedia knows a bit about this (Internet_Control_Message_Protocol), but if you're serious about this kind of low level network stuff, you should work through a thorough introduction like volume 1 of Douglas Comer's TCP/IP book.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

rosy Jovita wrote:Hi all,

anybody can tell me what's the function of these two?

icmp.seq=100;
icmp.id=0;

i have no idea on how does it works, sorry..i'm still new to java networking.
thanks for help.


You can look these up (icmp), but these are not important to your underlying problem that the Traceroute program does not handle all the types you are receiving.
have you added code to Traceroute.java to handle packets of type ICMP_REDIRECT_TOSHOST ?
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
yeah, i have added that code but the output are still more or less the same like the sample that i
sent to you..
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

ok. if you now print out p.type by adding


after


what numbers then come in your output? I expect you will need to handle more types.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
tim,

i got 11 and 3
but what is that for?
i'm getting more and more confuse with this.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
rosy Jovita wrote:i got 11 and 3
but what is that for?

Go to the javadocs for the ICMPPacket class, find a link called "Constant Field Values" and click on it. That will take you to a table that lists those values (note that there's some duplication of values in the table).

Note that 3 is ICMP_REDIRECT_TOSHOST, which Tim asked you about earlier. 11 might be ICMP_UNREACH_TOSNET.

To understand these, and to know how to handle them, a thorough reading of an ICMP tutorial is probably required.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
ulf,

thanks for that, have just realize of that. 11 is the Time exceed and 3 is icmp unreach port.
now i understand what is really going on.
The packet does not reach the destination.
Are you having the same problem too Tim?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

rosy Jovita wrote:ulf,

thanks for that, have just realize of that. 11 is the Time exceed and 3 is icmp unreach port.
now i understand what is really going on.
The packet does not reach the destination.
Are you having the same problem too Tim?


No, once I handled the 3, my Traceroute worked. Post your current code here and I'll compare it to mine.
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Tim,

this is what i get:

0: \Device\NPF_GenericDialupAdapter(Adapter for generic dialup and VPN capture)
datalink: EN10MB(Ethernet)
1: \Device\NPF_{6BDC6AC4-C6EF-4273-89B3-1492C5960423}(Broadcom 802.11g Network Adapter (Microsoft's Packet Scheduler) )
datalink: EN10MB(Ethernet)
2: \Device\NPF_{94F2D365-F539-4834-AC2E-1F5A2BEF0F54}(Realtek RTL8139 Family Fast Ethernet Adapter (Microsoft's Packet Scheduler) )
datalink: EN10MB(Ethernet)
type received 11
0: 10.48.224.1/10.48.224.1
type received 3
1: 10.255.4.9/10.255.4.9
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I meant, post the code to your current Traceroute.java
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
hi tim, sorry for the late reply.

this is my current code:

rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Hi Tim,

I get it works on ubuntu, it shows me number of hops and the ip address.
But it doesn't works on windows, I think so because each time i run it just showed two hops only.
but it's okay, I'll work hard for that.
and, do you think that it's possible to display the round trip times too?
Thanks Tim for your help, thank you very much
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Hi Tim,

I've tried again on my friend's computer.
He's the admin of that pc but still i got arrayIndexOutOfBoundException.
Do you have any idea what is going on?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
In which code are you getting the exception? What is the array index in question? How long is the array in question?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

rosy Jovita wrote:Hi Tim,

I've tried again on my friend's computer.
He's the admin of that pc but still i got arrayIndexOutOfBoundException.
Do you have any idea what is going on?


So, he might have admin access, but maybe there is only one device, in which case the command Traceroute 1 216.239.61.104 would get an array index out of bound.

so, try Traceroute 0 216.239.61.104

that is all I can think of.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Someone please help me with the traceroute using jpcap