Sending ICMP packet:
Hi,
I want to send an ICMP packet with Java. I am able to send UDP packets but i could not find a way to send ICMP packets.
Can anyone plz help.
Thanks in advance.
Hi,
I want to send an ICMP packet with Java. I am able to send UDP packets but i could not find a way to send ICMP packets.
Can anyone plz help.
Thanks in advance.
> IIRC the isReachable() method in InetAddress uses
> icmp if possible, but falls back on udp or so.
I've had horrible luck with that. I've never been able to be able to get it to return true for anything other than localhost, even when ping works fine.
> IIRC the isReachable() method in InetAddress uses
> icmp if possible, but falls back on udp or so.
No. That was the plan, but the WINSOCK API doesn't support it properly, and you need root privilege on Unix, so end of plan. It just uses TCP to port 7.
But pings are usually a complete waste of time. If you want to know whether a host is up, just try connecting to the server you want to connect to. Then you (a) know the host is up, (b) know the server is up, and (c) have a usable connection. The ping only does a third of that, even if you could do it, and there would still a timing-window problem and the possibility that the server isn't listening.
The problem is that i want to send some data using ICMP Packets.
I used UDP packets but they are blocked by firewall. So i need to send the very small code using ICMP packet. Earlier we used vc++ and we did it, but now we have shifted application to java and i want the same to work in java.
Is it really impossible? if so then what should i do...
> The problem is that i want to send some data using
> ICMP Packets.
> I used UDP packets but they are blocked by firewall.
> So i need to send the very small code using ICMP
> packet. Earlier we used vc++ and we did it, but now
> we have shifted application to java and i want the
> same to work in java.
>
> Is it really impossible? if so then what
> should i do...
Native code. You have a C/C++ library that does it? Write JNI to that
> So, you want to say that there is no way to do that
> in Java...
I don't want to, but I don't really have a choice. My hands are tied by reality I'm afraid
http://www.koders.com/java/fid93EB3022C6BCB6EAC082BE8CB13E925DB2F0266B.aspx?s=icmp
I think that uses JNI for Win32 (HWAddr etc)
yup
http://www.koders.com/c/fid4304E1C9A704965DAFAE6504718A83BC193287D3.aspx
Message was edited by:
jGardner
> http://www.koders.com/java/fid93EB3022C6BCB6EAC082BE8C
> B13E925DB2F0266B.aspx?s=icmp
>
> I think that uses JNI for Win32 (HWAddr etc)
>
> yup
> http://www.koders.com/c/fid4304E1C9A704965DAFAE6504718
> A83BC193287D3.aspx
>
> Message was edited by:
> jGardner
http://www.koders.com/java/fid7EF10E94485F17CEAF71A8FE68A205DB3470A25C.aspx?s=icmp
Has some native methods in it
edit: interesting. I was in the process of replying to your post, and although I'd already quoted your pre-edit post, Jive was smart enough to quote the edited version
Message was edited by:
georgemc
I am too tired to deal with sockets this early in the morning; that package looks like it might be of use.
All I can tell you is this: if you are going to use JNI to do it, and you are using windows, do not write it yourself; Winsock has the most ridiculously stupid API with the possible exception of the windows.h GUI API. Your eyes will hemorrhage.
> yes i understand that we have to use something other
> than java to do the real task.
And JGardener gave a good pointer to something that will help. Also, in a previous post you said you'd done this before in VC++, so if you've got that dll kicking about, you could re-use that and write a bit of JNI for it
> The problem is that i want to send some data using
> ICMP Packets.
Why would you want to do that?
> I used UDP packets but they are blocked by firewall.
> So i need to send the very small code using ICMP
> packet. Earlier we used vc++ and we did it, but now
> we have shifted application to java and i want the
> same to work in java.
Many firewall configurations block ping too. The fact that yours doesn't seem to do so now, doesn't mean it won't later on, and consequently break your app.
Again, what is it that you want to accomplish?
As mentioned, there are better ways to check for a live machine/server in Java accross firewalls, using simply HTTP.
i undestand yr concern but there is something that i want to sent. I cannot reveal the reason because of some issues. I want to send a code word or password using ICMP packets to a secured sever. The server only allows ICMP packets and blocks anything else.
I don't think he quite understands what ICMP is designed to do...
http://www.koders.com/info.aspx?c=ProjectInfo&pid=5B5A1PCAKW68H26USWFR9ZHQSH
I'll be damned. I wonder if the native code is on a low enough level where it wont even matter what platform you did it on? they have hardware drivers there too
http://www.koders.com/java/fidA592B0378941A9D1A1A3F3C8BDEF280CEFBF504B.aspx
> The server
> only allows ICMP packets and blocks anything else.
Then you can't do that using only Java.
Runtime .exec ping or fping, or use JNI.
> Is this a flow in java that we cannot create and send
> ICMP packets in java.
Not a flaw. It just doesn't do it. ICMP isn't really designed to carry application data, using it to get through a firewall is a bit hacky
> > Is this a flow in java that we cannot create and
> send
> > ICMP packets in java.
>
> Not a flaw. It just doesn't do it. ICMP isn't really
> designed to carry application data, using it to get
> through a firewall is a bit hacky
QFT.
Nistel: http://www.ietf.org/rfc/rfc0792.txt
Chances are it is going to downright ignore anything that isn't defined there.
i am not talking about sending application data. i want to sent a password. It can be sent as simultaneous ICMP Packets after one second and can be decoded at the other end... something like this i think...
> i am not talking about sending application data. i
> want to sent a password. It can be sent as
> simultaneous ICMP Packets after one second and can be
> decoded at the other end... something like this i
> think...
Chances are it will just give you back ICMP 12.
> i am not talking about sending application data. i
> want to sent a password.
A password is application data!
> It can be sent as
> simultaneous ICMP Packets after one second and can be
> decoded at the other end... something like this i
> think...
You might get it to work. Wouldn't really be guaranteed though, and as pointed out before, there's no reason on Earth to think that it might just stop working in the future when your router is reconfigured, replaced or whatever
can i use INetAddress Class. I think it send ICMP packets when checking the isReacheable() method
Plus ICMP is pretty much limited to 64 bits (8 octets; 8 letters). That's not even enough to say "Hello World" much less the more grammatically correct, "Hello, world!"
> can i use INetAddress Class. I think it send ICMP
> packets when checking the isReacheable() method
I'm going to say "no". Forget leveraging ICMP for this, if you ever did get it to work it'd be pure coincidence, and extremely fragile. Why do you think you need ICMP rather than some other protocol?
The problem is that you are trying to use a protocol for something that it was NOT designed for.
1. Your firewall is most likely to understand one of the 3 to 5 ICMP messages that are defined. It is probably going to reject anything else.
2. ICMP is designed for request/feedback, not data transfer.
3. ICMP tends to use more NUMBERS than actual characters.
Read: http://www.ietf.org/rfc/rfc0792.txt
If their network doesn't accept anything other than ICMP, it is because it doesn't want to talk to you. You need to fix the network, not work around it.
> because the target server's firewall does not allow
> any other protocol than ICMP
Then if that server is to be involved in something that does require another protocol, the firewall needs to be altered. There are other ways to secure data than simply blocking as many protocols as you can get away with. You have a genuine business case for TCP/IP to be opened up here
> > because the target server's firewall does not
> allow
> > any other protocol than ICMP
>
> Then if that server is to be involved in something
> that does require another protocol, the firewall
> needs to be altered. There are other ways to secure
> data than simply blocking as many protocols as you
> can get away with. You have a genuine business case
> for TCP/IP to be opened up here
Agreed...
https://www.cia.gov/ <-- even they allow TCP over port 80!
> because the target server's firewall does not allow
> any other protocol than ICMP
I find it strange that a secure server will allow ICMP traffic, and not HTTP/HTTPS.
AFAIK, there are much more security issues with allowing ICMP traffic due to the implications of raw sockets access (variants of the Ping of Death, smurf attacks, etc..)
> > because the target server's firewall does not
> allow
> > any other protocol than ICMP
>
> I find it strange that a secure server will
> allow ICMP traffic, and not HTTP/HTTPS.
I find it not just strange but unbelievable. If a server doesn't accept UDP or TCP, it isn't there for all practical purposes.
Have you considered TCP for this task?
Can you also tell us how the server manages to read this ICMP packet?
I agree with u all but i the problem is that i still have to send ICMP packets, i cannot change the whole network because it is not mine and nor can i change the process, i have to do my job and that is to send ICMP packets and that is why i am asking for help.
> I agree with u all but i the problem is that i still
> have to send ICMP packets, i cannot change the whole
> network because it is not mine and nor can i change
> the process, i have to do my job and that is to send
> ICMP packets and that is why i am asking for help.
YOU CANNOT USE ICMP FROM JAVA DIRECTLY.
THIS IS WHAT I TOLD YOU IN REPLY NUMBER FOUR. NOTHING HAS CHANGED SINCE THEN.
Okay? Really.
If you want to try and use some native code to do that then do that. Your requirements are not what you say they are. You are very mixed up. "Authentication" via ICMP is not happening. That has been discussed in detail now but that does not change the fact that
YOU CANNOT USE ICMP FROM JAVA DIRECTLY.
Okay? Did you get that this time?
But the facts of that aside you really, really, really, really, really need to get a better handle on your requirements because they are also bogus.
Than what the hell is this:
public class PortUnreachableException
extends SocketException
Signals that an ICMP Port Unreachable message has been received on a connected datagram.
Well, if java.net has a exception for ICMP, I can supose that i can have something for ICMP using Java
> Than what the hell is this:
>
> public class PortUnreachableException
> extends SocketException
>
> Signals that an ICMP Port Unreachable message has
> been received on a connected datagram.
>
> Well, if java.net has a exception for ICMP,
That exception is not encountered by your using ICMP (as the documentation makes VERY clear) it is possibly encountered when you are using UDP.
> I can
> supose that i can have something for ICMP using Java
Yes, you are right, we are all lying to you. You can use ICMP in Java by using the java.net.icmp package.
Good luck!
Very tiresome.
To the OP: it is time to stop floundering around and do some research.
(a) Java does not let you send ICMP in any way shape or form.
(b) ICMP doesn't let you write application or authentication data, from any language.
(c) No server can exist, practically speaking, that only speaks ICMP.
(d) The assertion that the server does authentication by ICMP is therefore 100% grade A nonsense.
What is the basis for this belief? What you are saying, and/or what you have been asked to do, is truly impossible.
Find someone who knows the system and actually knows that they are talking about.
> if u do not know any thing than don't try to be
> oversmart
The problem is not us being overly smart, the problem is that you are overly dumb. Try and see if you can get that fixed somehow.
And there is only person in this thread who "do not know any thing" and that is "u".
What if we do know something?
Have a look at RFC 792 as you were advised to do some time ago. Also see this from RFC791: 'ICMP is used from gateways to hosts and between hosts to report errors and make routing suggestions'.
That's it. No data payload. Not used for authenication. Period.
And stop being rude to the people who are trying to help you.
i am not being rude... if i am trying to explain something that i want to do....
i know it is a bit different but it is not impractical...
> i am not being rude...
Yes you are. You have been rude several times now.
>if i am trying to explain
> something that i want to do....
Yes. We understand what you are asking but what you want is impossible.
Yes, i understand...
ok thanks everyone for your help and time... i think i have to find some native api and use that...
> Yes, i understand...
> ok thanks everyone for your help and time... i think
> i have to find some native api and use that...
That won't work either.
> why so... if i could use the native api and call that
> using JNI... won't it work
Because you can't use ICMP as a data protocol.
This has been mentioned several times now and ejp provided a link to the RFC in question which explains this further (if you continue to doubt us) in reply # 48.
> why so... if i could use the native api and call that
> using JNI... won't it work
No, it won't.
JNI was a suggestion for PING functionality, as was Runtime.exec with the ping or fping command.
PING uses ICMP, but only as echo packets. You want to send data (passw) using ICMP. That's a whole different story.
I am sorry to say, but nor your requirements, nor your description of your environment make any sense.
i am not doubting you... i am very much confused about everything... i think u are right and i should leave it...
anyway
thanks
> I agree with u all but i the problem is that i still
> have to send ICMP packets, i cannot change the whole
> network because it is not mine and nor can i change
> the process, i have to do my job and that is to send
> ICMP packets and that is why i am asking for help.
It is your duty - as part of this job - to inform the client that it cannot be done, then. No, I am not joking, and yes, that is exactly what I would do in your situation
> if u do not know any thing than don't try to be
> oversmart
Don't bother asking for help, then. I never had you down as one of those "I don't want correct answers, I just want to be told what I want to hear" merchants, what gives?
> i am not being rude... if i am trying to explain
> something that i want to do....
> i know it is a bit different but it is not
> impractical...
You are being rude, and somewhat foolish. Any idea how tiresome it is to be told repeatedly that your factual information is unacceptable? It's flattering in a way that you think an utterance from one of us will change reality, but it won't
Not impractical, no. Just impossible
> i am not doubting you... i am very much confused
> about everything... i think u are right and i should
> leave it...
> anyway
>
> thanks
*sigh* the last gasp of someone who is probably now convinced everyone else in this thread is a rude, arrogant @sshole who didn't want to help him. Ah well
> if u do not know any thing than don't try to be
> oversmart
Stop being a flaming pigfucking *******.
You have been given the facts. You have chosen to ignore them and whine about what you want, as if whining enough will change the facts.
Kindly go away and never come back.
>Stop being a flaming pigfucking *******.
I am not doing that but i think u are...
>You have been given the facts. You have chosen to ignore them and whine about what >you want, as if whining enough will change the facts.
i was just asking if anyone else knows.
>Kindly go away and never come back.
i have no need to go. If u feel so bad then you may go and never come back if u wish.
> >Stop being a flaming pigfucking *******.
>
> I am not doing that but i think u are...
>
> >You have been given the facts. You have chosen to
> ignore them and whine about what >you want, as if
> whining enough will change the facts.
>
> i was just asking if anyone else knows.
Which is basically you saying you don't believe anyone else in this thread. Which is quite insulting, really
> i don't know why are u trying to expand the whole
> matter.
To underline the point that being insulting toward people who don't give you acceptable answers won't change the fact that certain things just can't be done. Last year, there was a guy asking how to use Java to control the temp. of his CPU. When I told him it couldn't be done, he started following me to other threads telling the posters that I was disparaging and rude, and not to listen to me. As such, I take exception to posters who refuse to accept the answers they've asked for, just because they don't like them
If you don't want to continue with this, you don't have to