364,083 Members | 5989 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

ICMP packets

Bob Rivers
P: n/a
Bob Rivers
Hi,

I was doing a research looking for Java solutions that are able to do
"ping".

I found old messages (and not so old ones), telling that Java was not
able to do that, because the API provided do not support raw sockets.
The only solution that I found was a "simulation" of a ping program
doing a UDP request to a server on port 7.

So I decided to read the API (1.4.2) and I found that the package
"java.net" is able to send ICMP packets.

Actually, and this is my question, I only found an exception that:
"Signals that an ICMP Port Unreachable message has been received on a
connected datagram."
(http://java.sun.com/j2se/1.4.2/docs/...xception.html).

Well, if the package has a exception for ICMP, I can supose that now I
am able to talk ICMP using Java
(http://java.sun.com/j2se/1.4.2/docs/...amSocket.html).

Am I right?

And finally: does someone did something related to this, using the new
api? Is it possible to post an example?

Thanks,

Bob Rivers
Sao Paulo - Brazil
Jul 17 '05 #1
Share this Question
Share on Google+
13 Replies


Glen Herrmannsfeldt
P: n/a
Glen Herrmannsfeldt

"Bob Rivers" <bobrivers@pobox.com> wrote in message
news:aa669e9b.0310230752.da4f436@posting.google.co m...[color=blue]
> Hi,
>
> I was doing a research looking for Java solutions that are able to do
> "ping".
>
> I found old messages (and not so old ones), telling that Java was not
> able to do that, because the API provided do not support raw sockets.
> The only solution that I found was a "simulation" of a ping program
> doing a UDP request to a server on port 7.[/color]

Under Unix, at least, ping requires the setuid privilege. That means that
the ping program has the full authority to do anything to the system that it
wants to. Presumably the code has been carefully checked so that it
doesn't do anything wrong.

It would be horrible to run the JVM as setuid root, and that would be
required for the abiltity to do ping. It is certainly possible to execute
/usr/sbin/ping if one really wants to do it. I am sure that other
operating systems have similar protections protecting the system against
unauthorized access.

I do wonder, though, why this subject comes up so often. What advantage
could there be to a program with the ability to do ping? It is useful for
network administrators to check that the network is working properly.
Though more and more firewalls block both ping and the TCP and UDP echo
ports, reducing the usefulness of these features.

-- glen


Jul 17 '05 #2

Phil...
P: n/a
Phil...
can't you just try to open a dummy URL on the server
and look at the result?


"Glen Herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:Z9Ulb.3628$mZ5.22428@attbi_s54...[color=blue]
>
> "Bob Rivers" <bobrivers@pobox.com> wrote in message
> news:aa669e9b.0310230752.da4f436@posting.google.co m...[color=green]
> > Hi,
> >
> > I was doing a research looking for Java solutions that are able to do
> > "ping".
> >
> > I found old messages (and not so old ones), telling that Java was not
> > able to do that, because the API provided do not support raw sockets.
> > The only solution that I found was a "simulation" of a ping program
> > doing a UDP request to a server on port 7.[/color]
>
> Under Unix, at least, ping requires the setuid privilege. That means that
> the ping program has the full authority to do anything to the system that[/color]
it[color=blue]
> wants to. Presumably the code has been carefully checked so that it
> doesn't do anything wrong.
>
> It would be horrible to run the JVM as setuid root, and that would be
> required for the abiltity to do ping. It is certainly possible to[/color]
execute[color=blue]
> /usr/sbin/ping if one really wants to do it. I am sure that other
> operating systems have similar protections protecting the system against
> unauthorized access.
>
> I do wonder, though, why this subject comes up so often. What advantage
> could there be to a program with the ability to do ping? It is useful for
> network administrators to check that the network is working properly.
> Though more and more firewalls block both ping and the TCP and UDP echo
> ports, reducing the usefulness of these features.
>
> -- glen
>
>[/color]


Jul 17 '05 #3

Amey Samant
P: n/a
Amey Samant
"Glen Herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message news:<Z9Ulb.3628$mZ5.22428@attbi_s54>...[color=blue]
> "Bob Rivers" <bobrivers@pobox.com> wrote in message
> news:aa669e9b.0310230752.da4f436@posting.google.co m...[/color]
[color=blue]
> I do wonder, though, why this subject comes up so often. What advantage
> could there be to a program with the ability to do ping? It is useful for
> network administrators to check that the network is working properly.
> Though more and more firewalls block both ping and the TCP and UDP echo
> ports, reducing the usefulness of these features.
>
> -- glen[/color]

hi
nowadays users are also becoming smarter and demand more. ;)
i saw one application (day-to-day life type) which uses ping ....

guesss
..
..
..
..
..
..
..
games.yahoo.com :D
if you are playing games on yahoo say for eg. pool & if your partner
is not responding ..... you can ping his machine to know if its the
network problem.
it shows ping stats from your machine to games server & from games
server to partner s machine.

but if you wanna opt for simpler option you can invoke ping.exe or
ping binary with exec & capture & display results

regards
amey
Jul 17 '05 #4

Bob Rivers
P: n/a
Bob Rivers
> I do wonder, though, why this subject comes up so often. What advantage[color=blue]
> could there be to a program with the ability to do ping? It is useful for
> network administrators to check that the network is working properly.
> Though more and more firewalls block both ping and the TCP and UDP echo
> ports, reducing the usefulness of these features.[/color]

Hi,

The advantage of ping usage, is because with it I can:

1) Check if my server/network is down or not;
2) Get metrics about my server/network perfomance (minimum, maximun
and average round trip times);
3) Get metrics about my server/network quality (packets sent, received
and loss percentage)

So, a small application could give me lots of information. So this is
why this subject comes up often, imho.

Of course I could try to open an URL. If I got a response, I could
supose that my server/network is working properly. I also could use a
timer to mesure the start/stop and then gather the server/network
performance. I could also try to use traceroute command.

But this is the point. I do not want to write everything. If J2SDK
1.4.2 is able to provide ICMP, and then I could build a ping
application, I should give it a try.

And about firewalls, I do not agree. Its true that more and more
sysops are closing ports and dennying this kind of service, and they
should do it.

But this is not 100% true. Inside companys, sysops should be able to
use this kind of solution. At least they could open it to a limited
range of addresses. So I can keep it controlled, and not loose a
great/simple tool.

Thanks for replying.

Bob
Ps.: Sorry my poor english. It's difficult to argue in a foregin
language.
Jul 17 '05 #5

Phil...
P: n/a
Phil...

"Bob Rivers" <bobrivers@pobox.com> wrote in message
news:aa669e9b.0310240532.76f2e801@posting.google.c om...[color=blue][color=green]
> > I do wonder, though, why this subject comes up so often. What[/color][/color]
advantage[color=blue][color=green]
> > could there be to a program with the ability to do ping? It is useful[/color][/color]
for[color=blue][color=green]
> > network administrators to check that the network is working properly.
> > Though more and more firewalls block both ping and the TCP and UDP echo
> > ports, reducing the usefulness of these features.[/color]
>
> Hi,
>
> The advantage of ping usage, is because with it I can:
>
> 1) Check if my server/network is down or not;
> 2) Get metrics about my server/network perfomance (minimum, maximun
> and average round trip times);
> 3) Get metrics about my server/network quality (packets sent, received
> and loss percentage)[/color]

What kind of server do you have that doesn't give you packet counts?
[color=blue]
> So, a small application could give me lots of information. So this is
> why this subject comes up often, imho.
>
> Of course I could try to open an URL. If I got a response, I could
> supose that my server/network is working properly. I also could use a
> timer to mesure the start/stop and then gather the server/network
> performance. I could also try to use traceroute command.
>
> But this is the point. I do not want to write everything. If J2SDK
> 1.4.2 is able to provide ICMP, and then I could build a ping
> application, I should give it a try.
>
> And about firewalls, I do not agree. Its true that more and more
> sysops are closing ports and dennying this kind of service, and they
> should do it.
>
> But this is not 100% true. Inside companys, sysops should be able to
> use this kind of solution. At least they could open it to a limited
> range of addresses. So I can keep it controlled, and not loose a
> great/simple tool.
>
> Thanks for replying.
>
> Bob
> Ps.: Sorry my poor english. It's difficult to argue in a foregin
> language.[/color]


Jul 17 '05 #6

Phil...
P: n/a
Phil...

"Bob Rivers" <bobrivers@pobox.com> wrote in message
news:aa669e9b.0310240532.76f2e801@posting.google.c om...[color=blue][color=green]
> > I do wonder, though, why this subject comes up so often. What[/color][/color]
advantage[color=blue][color=green]
> > could there be to a program with the ability to do ping? It is useful[/color][/color]
for[color=blue][color=green]
> > network administrators to check that the network is working properly.
> > Though more and more firewalls block both ping and the TCP and UDP echo
> > ports, reducing the usefulness of these features.[/color]
>
> Hi,
>
> The advantage of ping usage, is because with it I can:
>
> 1) Check if my server/network is down or not;
> 2) Get metrics about my server/network perfomance (minimum, maximun
> and average round trip times);
> 3) Get metrics about my server/network quality (packets sent, received
> and loss percentage)[/color]

What kind of server do you have that doesn't give you packet counts?
[color=blue]
> So, a small application could give me lots of information. So this is
> why this subject comes up often, imho.
>
> Of course I could try to open an URL. If I got a response, I could
> supose that my server/network is working properly. I also could use a
> timer to mesure the start/stop and then gather the server/network
> performance. I could also try to use traceroute command.
>
> But this is the point. I do not want to write everything. If J2SDK
> 1.4.2 is able to provide ICMP, and then I could build a ping
> application, I should give it a try.
>
> And about firewalls, I do not agree. Its true that more and more
> sysops are closing ports and dennying this kind of service, and they
> should do it.
>
> But this is not 100% true. Inside companys, sysops should be able to
> use this kind of solution. At least they could open it to a limited
> range of addresses. So I can keep it controlled, and not loose a
> great/simple tool.
>
> Thanks for replying.
>
> Bob
> Ps.: Sorry my poor english. It's difficult to argue in a foregin
> language.[/color]


Jul 17 '05 #7

Glen Herrmannsfeldt
P: n/a
Glen Herrmannsfeldt

"Amey Samant" <ameyas7@yahoo.com> wrote in message
news:669e50b8.0310231954.63cbb6f3@posting.google.c om...[color=blue]
> "Glen Herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message[/color]
news:<Z9Ulb.3628$mZ5.22428@attbi_s54>...[color=blue][color=green]
> > "Bob Rivers" <bobrivers@pobox.com> wrote in message
> > news:aa669e9b.0310230752.da4f436@posting.google.co m...[/color]
>[color=green]
> > I do wonder, though, why this subject comes up so often. What[/color][/color]
advantage[color=blue][color=green]
> > could there be to a program with the ability to do ping? It is useful[/color][/color]
for[color=blue][color=green]
> > network administrators to check that the network is working properly.
> > Though more and more firewalls block both ping and the TCP and UDP echo
> > ports, reducing the usefulness of these features.[/color][/color]
[color=blue]
> nowadays users are also becoming smarter and demand more. ;)
> i saw one application (day-to-day life type) which uses ping ....[/color]
[color=blue]
> games.yahoo.com :D
> if you are playing games on yahoo say for eg. pool & if your partner
> is not responding ..... you can ping his machine to know if its the
> network problem.
> it shows ping stats from your machine to games server & from games
> server to partner s machine.[/color]

With the number of NAT routers that block ICMP, that isn't so useful. Even
UDP probably isn't so useful for the same reason. I suppose, though, I
would try both UDP echo, and TCP echo. Probably better would be UDP to a
specific port opened by the server for that purpose.

-- glen


Jul 17 '05 #8

FISH
P: n/a
FISH
ameyas7@yahoo.com (Amey Samant) wrote in message news:<669e50b8.0310231954.63cbb6f3@posting.google. com>...
[snipped...][color=blue]
> games.yahoo.com :D
> if you are playing games on yahoo say for eg. pool & if your partner
> is not responding ..... you can ping his machine to know if its the
> network problem.
> it shows ping stats from your machine to games server & from games
> server to partner s machine.[/color]

Yahoo IM and Chat use their own bespoke ping scheme, which are just
regular TCP/IP packets. I suspect Yahoo Games do the same (as they
also rely on YMSG, to the best of my knowledge!)

(If you're at all interested in YMSG interals:
"http://jymsg9.sourceforge.net/" (Java Yahoo IM/Chat API) or
"http://libyahoo2.sourceforge.net/" (same, but for C) )

[color=blue]
> but if you wanna opt for simpler option you can invoke ping.exe or
> ping binary with exec & capture & display results[/color]

Realistically Java isn't really intended for doing the kind of work
that would require access to ping. If verifying a connection is what
you need to do, you can always build in a custom ping mechanism into
whatever application you are writing - like Yahoo have done.

-FISH- ><>
Jul 17 '05 #9

Matt Smith
P: n/a
Matt Smith
Bob Rivers wrote:[color=blue]
> Hi,
>
> I was doing a research looking for Java solutions that are able to do
> "ping".
>
> I found old messages (and not so old ones), telling that Java was not
> able to do that, because the API provided do not support raw sockets.
> The only solution that I found was a "simulation" of a ping program
> doing a UDP request to a server on port 7.
>
> So I decided to read the API (1.4.2) and I found that the package
> "java.net" is able to send ICMP packets.
>
> Actually, and this is my question, I only found an exception that:
> "Signals that an ICMP Port Unreachable message has been received on a
> connected datagram."
> (http://java.sun.com/j2se/1.4.2/docs/...xception.html).
>
> Well, if the package has a exception for ICMP, I can supose that now I
> am able to talk ICMP using Java
> (http://java.sun.com/j2se/1.4.2/docs/...amSocket.html).
>
> Am I right?
>
> And finally: does someone did something related to this, using the new
> api? Is it possible to post an example?
>
> Thanks,
>
> Bob Rivers
> Sao Paulo - Brazil[/color]

Although this topic seems to have headed off in a different direction,
the ICMP exception you refer to does not infer that Java can handle ICMP
directly. For example, if your code attempts to connect to a TCP port
that does not exist on a remote server, the server will return an "ICMP
Port Unreachable" message. That is a standard TCP/UDP operation. So
Java only handles this type of operational return message.

Just wanted to give you the "FYI"

-Matt

Jul 17 '05 #10

Bob Rivers
P: n/a
Bob Rivers
Matt Smith <matt.smith@uconn.edu> wrote in message
[color=blue]
> Although this topic seems to have headed off in a different direction,
> the ICMP exception you refer to does not infer that Java can handle ICMP
> directly. For example, if your code attempts to connect to a TCP port
> that does not exist on a remote server, the server will return an "ICMP
> Port Unreachable" message. That is a standard TCP/UDP operation. So
> Java only handles this type of operational return message.
>
> Just wanted to give you the "FYI"
>
> -Matt[/color]

Thanks,

Bob
Jul 17 '05 #11

Cory
P: n/a
Cory
bobrivers@pobox.com (Bob Rivers) wrote in message news:<aa669e9b.0310230752.da4f436@posting.google.c om>...[color=blue]
> Hi,
>
> I was doing a research looking for Java solutions that are able to do
> "ping".
>
> I found old messages (and not so old ones), telling that Java was not
> able to do that, because the API provided do not support raw sockets.
> The only solution that I found was a "simulation" of a ping program
> doing a UDP request to a server on port 7.
>
> So I decided to read the API (1.4.2) and I found that the package
> "java.net" is able to send ICMP packets.
>
> Actually, and this is my question, I only found an exception that:
> "Signals that an ICMP Port Unreachable message has been received on a
> connected datagram."
> (http://java.sun.com/j2se/1.4.2/docs/...xception.html).
>
> Well, if the package has a exception for ICMP, I can supose that now I
> am able to talk ICMP using Java
> (http://java.sun.com/j2se/1.4.2/docs/...amSocket.html).
>
> Am I right?
>
> And finally: does someone did something related to this, using the new
> api? Is it possible to post an example?
>
> Thanks,
>
> Bob Rivers
> Sao Paulo - Brazil[/color]


If you want to get really hardcore, you can dl JPcap:
http://netresearch.ics.uci.edu/kfuji...doc/links.html

Then you'll be able to control every network layer on your machine
from within Java code. Note: JPcap is not portable, so you need to dl
different versions for different OS'.

-Cory
Jul 17 '05 #12

Sam
P: n/a
Sam
coryvirok@hotmail.com (Cory) wrote in message[color=blue]
> If you want to get really hardcore, you can dl JPcap:
> http://netresearch.ics.uci.edu/kfuji...doc/links.html
>
> Then you'll be able to control every network layer on your machine
> from within Java code. Note: JPcap is not portable, so you need to dl
> different versions for different OS'.
>
> -Cory[/color]

Hi Cory,

Have you tried the ping solution there? I've given it an intial try,
but no luck - nothing gets put out to the network.

There is a comment in the source about having to set the Ethernet
header in windows, but the call to the raw socket (which is a JNI call
to winpcap) on accepts IPPacket, so it's impossible to specify
(although an EthernetPacket Java class is provided as an extension to
a DataLink class).

Sam90
Jul 17 '05 #13

Krishna
P: 1
I have extended socket and tried connecting to a host using
Socket(address,port) constructor. If the error thrown is ConnectException it means though the server is up the connection to that port is not entertained.
If an UnknownHostException is thrown this simply means that the host is down/ the route is down.

This is the simplest ping simulation i could come up with. Following is the code...


import java.io.IOException;
import java.net.*;
public class Pingo_client extends Socket{

public static void main(String[] args) {
try {
Pingo_client p1=new Pingo_client(InetAddress.getLocalHost(),2559);
System.out.println("the remote host is UP");
p1.close();
} catch (UnknownHostException e) {
System.out.println("Remote host down");
} catch (IOException e) {
e.printStackTrace();
}

}
Pingo_client(InetAddress address, int port){
try {
new Socket(address,port);
} catch (ConnectException e) {
// TODO Auto-generated catch block
System.out.println("Connection refused");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Jun 16 '06 #14

Post your reply

Help answer this question



Didn't find the answer to your Java question?

You can also browse similar questions: Java java icmp