Results 1 to 8 of 8

Thread: Ping in Java

  1. #1
    VeasMKII's Avatar
    VeasMKII is offline Member
    Join Date
    Jan 2009
    Posts
    18
    Rep Power
    0

    Default Ping in Java

    Hi, i've been trying for a few hours up till now creating a simple Ping program.

    The idea was to ping an address and to keep pinging the address periodically to keep track of the ping response times.

    I was then going to set this as a system tray icon for a useful latency indicator.

    Well, apparently i've hit a brick wall as i've read Java doesn't support ICMP echo requests (Ping).

    I've tried the following instead,
    InetAddress.getByName(googledotcodotuk).isReachabl e(3000);

    However this doesn't work on basically any computer other than my own. (Something to do with this connection type disabled be default?)

    I've tried another method which seems to spawn ping.exe and send in command to get the native ping utility (windows) but this isn't really ideal for a number of reasons. Mainly i've no idea how to extract the responses, it defaults to four pings and i'd like to use this on more than just a windows platform.

    So is there any way i could ping a general server in a way that i could extract the latency as an interger value? Even if it only runs on Windows.
    Last edited by VeasMKII; 01-18-2009 at 12:58 AM.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default No Java support for ping

    As far as I can tell, there is no native support for this kind of service (I'm not a expert). Try Googling "java ping code"... plenty of info.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    VeasMKII's Avatar
    VeasMKII is offline Member
    Join Date
    Jan 2009
    Posts
    18
    Rep Power
    0

    Default

    Obviously this wasn't my first port of call ;) I'm thinking maybe it would be easier to figure out how to parse the latency from windows ping command.

    Does anyone have any idea how this is done?

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default hhhmmm...

    Not sure what your last comment meant... hhhmmm... you didn't find anything on Google to help you? I found the following:

    Using the Windoze ping command (just got to parse the results)

    Using the isReachable method:


    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    collinswis is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Re: Ping in Java

    Hw r u guyz

  6. #6
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: Ping in Java

    This seems like it would be a lot easier to write in a scripting language. Just write a simple script that runs the ping command in the background, and displays the results at the end; or doesn't display them, and just extracts the results you wish to view and places them in a file. The ping command is actually quite powerful in the way of options; ping -c 100 url/ip will ping the url/ip a 100 times before it stops. There are about 25 different options for the ping command. So it is not like you are limited to the basic ping. You can also change packet types and what not. Unless you were just looking for some Java practice, it kind of seems like you are reinventing the wheel here; or if you were actually looking to make some kind of rudimentary DDOS program. :)

    Whatever your goal is, good luck.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Ping in Java

    Hi Penguin! Did you check the dates? The OP posted in 2009 and is very likely ... unpingable.

    Post #5 may be an attempt to establish a post count before launching some spam our way. Or may just be a piece of internet randomness. Either way it's annoying for zombie threads to be reanimated like this.

    But since it is, ... The conventional wisdom (if you must use Java rather than a script as you propose, say to make a gui or control timing) seems to be to write the code in C and use JNI. See How to do a true Java ping from Windows? - Stack Overflow

  8. #8
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: Ping in Java

    Ahhh, I guess I have never really looked at the dates. Interesting thread though... I guess I am going to have to pay attention to the data from here on out. Lol. Though I must say, I am kind of glad you posted a solution to this; it is nice to know.

Similar Threads

  1. Ping pong game
    By adam405 in forum New To Java
    Replies: 8
    Last Post: 10-20-2010, 03:52 PM
  2. How to mesure ping delay in JAVA..?
    By sacr83 in forum Networking
    Replies: 4
    Last Post: 06-15-2008, 06:37 AM
  3. Replies: 1
    Last Post: 02-15-2008, 04:07 PM
  4. ping cmd
    By kishi in forum Advanced Java
    Replies: 2
    Last Post: 11-14-2007, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •