• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Someone please help me with the traceroute using jpcap

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your explanation, I got it.
I'll give it a try
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What, exactly, did you enter on the command line? It should be something like "java Traceroute 0 87.248.122.122".
 
Sheriff
Posts: 22850
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:D


 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:D



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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,

will you mind to post the sample output that you get?
Thanks.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so, I added



and now I'm getting something that resembles my tracert output.
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:D
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tim,

i got 11 and 3
but what is that for?
i'm getting more and more confuse with this.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant, post the code to your current Traceroute.java
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi tim, sorry for the late reply.

this is my current code:

 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:D
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic