ICMP packets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Rivers

    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
  • Glen Herrmannsfeldt

    #2
    Re: ICMP packets


    "Bob Rivers" <bobrivers@pobo x.com> wrote in message
    news:aa669e9b.0 310230752.da4f4 36@posting.goog le.com...[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


    Comment

    • Phil...

      #3
      Re: ICMP packets

      can't you just try to open a dummy URL on the server
      and look at the result?


      "Glen Herrmannsfeldt" <gah@ugcs.calte ch.edu> wrote in message
      news:Z9Ulb.3628 $mZ5.22428@attb i_s54...[color=blue]
      >
      > "Bob Rivers" <bobrivers@pobo x.com> wrote in message
      > news:aa669e9b.0 310230752.da4f4 36@posting.goog le.com...[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]


      Comment

      • Amey Samant

        #4
        Re: ICMP packets

        "Glen Herrmannsfeldt" <gah@ugcs.calte ch.edu> wrote in message news:<Z9Ulb.362 8$mZ5.22428@att bi_s54>...[color=blue]
        > "Bob Rivers" <bobrivers@pobo x.com> wrote in message
        > news:aa669e9b.0 310230752.da4f4 36@posting.goog le.com...[/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

        Comment

        • Bob Rivers

          #5
          Re: ICMP packets

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

          Comment

          • Phil...

            #6
            Re: ICMP packets


            "Bob Rivers" <bobrivers@pobo x.com> wrote in message
            news:aa669e9b.0 310240532.76f2e 801@posting.goo gle.com...[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]


            Comment

            • Phil...

              #7
              Re: ICMP packets


              "Bob Rivers" <bobrivers@pobo x.com> wrote in message
              news:aa669e9b.0 310240532.76f2e 801@posting.goo gle.com...[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]


              Comment

              • Glen Herrmannsfeldt

                #8
                Re: ICMP packets


                "Amey Samant" <ameyas7@yahoo. com> wrote in message
                news:669e50b8.0 310231954.63cbb 6f3@posting.goo gle.com...[color=blue]
                > "Glen Herrmannsfeldt" <gah@ugcs.calte ch.edu> wrote in message[/color]
                news:<Z9Ulb.362 8$mZ5.22428@att bi_s54>...[color=blue][color=green]
                > > "Bob Rivers" <bobrivers@pobo x.com> wrote in message
                > > news:aa669e9b.0 310230752.da4f4 36@posting.goog le.com...[/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


                Comment

                • FISH

                  #9
                  Re: ICMP packets

                  ameyas7@yahoo.c om (Amey Samant) wrote in message news:<669e50b8. 0310231954.63cb b6f3@posting.go ogle.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.sourcefo rge.net/" (Java Yahoo IM/Chat API) or
                  "http://libyahoo2.sourc eforge.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- ><>

                  Comment

                  • Matt Smith

                    #10
                    Re: ICMP packets

                    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

                    Comment

                    • Bob Rivers

                      #11
                      Re: ICMP packets

                      Matt Smith <matt.smith@uco nn.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

                      Comment

                      • Cory

                        #12
                        Re: ICMP packets

                        bobrivers@pobox .com (Bob Rivers) wrote in message news:<aa669e9b. 0310230752.da4f 436@posting.goo gle.com>...[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:


                        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

                        Comment

                        • Sam

                          #13
                          Re: ICMP packets

                          coryvirok@hotma il.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

                          Comment

                          • Krishna
                            New Member
                            • Jun 2006
                            • 1

                            #14
                            I have extended socket and tried connecting to a host using
                            Socket(address, port) constructor. If the error thrown is ConnectExceptio n it means though the server is up the connection to that port is not entertained.
                            If an UnknownHostExce ption 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.IOExcep tion;
                            import java.net.*;
                            public class Pingo_client extends Socket{

                            public static void main(String[] args) {
                            try {
                            Pingo_client p1=new Pingo_client(In etAddress.getLo calHost(),2559) ;
                            System.out.prin tln("the remote host is UP");
                            p1.close();
                            } catch (UnknownHostExc eption e) {
                            System.out.prin tln("Remote host down");
                            } catch (IOException e) {
                            e.printStackTra ce();
                            }

                            }
                            Pingo_client(In etAddress address, int port){
                            try {
                            new Socket(address, port);
                            } catch (ConnectExcepti on e) {
                            // TODO Auto-generated catch block
                            System.out.prin tln("Connection refused");
                            } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTra ce();
                            }
                            }
                            }

                            Comment

                            Working...