469,265 Members | 1,995 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,265 developers. It's quick & easy.

ICMP packets

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
13 23449

"Bob Rivers" <bo*******@pobox.com> wrote in message
news:aa*************************@posting.google.co m...
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.


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
can't you just try to open a dummy URL on the server
and look at the result?
"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message
news:Z9Ulb.3628$mZ5.22428@attbi_s54...

"Bob Rivers" <bo*******@pobox.com> wrote in message
news:aa*************************@posting.google.co m...
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.
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 #3
"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message news:<Z9Ulb.3628$mZ5.22428@attbi_s54>...
"Bob Rivers" <bo*******@pobox.com> wrote in message
news:aa*************************@posting.google.co m... 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


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
> 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.


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

"Bob Rivers" <bo*******@pobox.com> wrote in message
news:aa**************************@posting.google.c om...
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.
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)


What kind of server do you have that doesn't give you packet counts?
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 #6

"Bob Rivers" <bo*******@pobox.com> wrote in message
news:aa**************************@posting.google.c om...
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.
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)


What kind of server do you have that doesn't give you packet counts?
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 #7

"Amey Samant" <am*****@yahoo.com> wrote in message
news:66**************************@posting.google.c om...
"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message news:<Z9Ulb.3628$mZ5.22428@attbi_s54>...
"Bob Rivers" <bo*******@pobox.com> wrote in message
news:aa*************************@posting.google.co m...

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.

nowadays users are also becoming smarter and demand more. ;)
i saw one application (day-to-day life type) which uses ping .... 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.


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
am*****@yahoo.com (Amey Samant) wrote in message news:<66**************************@posting.google. com>...
[snipped...]
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.
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) )

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


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
Bob Rivers wrote:
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


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
Matt Smith <ma********@uconn.edu> wrote in message
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


Thanks,

Bob
Jul 17 '05 #11
bo*******@pobox.com (Bob Rivers) wrote in message news:<aa*************************@posting.google.c om>...
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

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
co*******@hotmail.com (Cory) wrote in message
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


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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andreas Pauley | last post: by
reply views Thread by T.C.McQueen | last post: by
reply views Thread by billiejoex | last post: by
1 post views Thread by Fotis | last post: by
5 posts views Thread by Tom Anderson | last post: by
2 posts views Thread by linuxsrbabu | last post: by
13 posts views Thread by Banupriya06 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.