This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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..
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?
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: 35438
9
posted
0
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.
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
posted
0
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: 35438
9
posted
0
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
posted
0
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
posted
0
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.
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
posted
0
Tim,
will you mind to post the sample output that you get?
Thanks.
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.
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.
and now I'm getting something that resembles my tracert output.
rosy Jovita
Ranch Hand
Joined: Jan 05, 2010
Posts: 45
posted
0
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
posted
0
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
posted
0
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
posted
0
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: 35438
9
posted
0
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.
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
posted
0
yeah, i have added that code but the output are still more or less the same like the sample that i
sent to you..
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
posted
0
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: 35438
9
posted
0
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
posted
0
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?
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
posted
0
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
I meant, post the code to your current Traceroute.java
rosy Jovita
Ranch Hand
Joined: Jan 05, 2010
Posts: 45
posted
0
hi tim, sorry for the late reply.
this is my current code:
rosy Jovita
Ranch Hand
Joined: Jan 05, 2010
Posts: 45
posted
0
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
posted
0
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: 35438
9
posted
0
In which code are you getting the exception? What is the array index in question? How long is the array in question?
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.