Results 1 to 8 of 8
Thread: Ping in Java
- 01-18-2009, 12:53 AM #1
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.
- 01-18-2009, 03:18 AM #2
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-18-2009, 05:08 AM #3
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?
- 01-19-2009, 02:28 AM #4
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 10-13-2012, 01:38 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
Re: Ping in Java
Hw r u guyz
- 10-14-2012, 03:07 AM #6
Member
- Join Date
- Oct 2012
- Location
- Tempe, Arizona
- Posts
- 77
- Blog Entries
- 12
- Rep Power
- 0
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.
- 10-14-2012, 04:39 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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
- 10-14-2012, 09:51 PM #8
Member
- Join Date
- Oct 2012
- Location
- Tempe, Arizona
- Posts
- 77
- Blog Entries
- 12
- Rep Power
- 0
Similar Threads
-
Ping pong game
By adam405 in forum New To JavaReplies: 8Last Post: 10-20-2010, 03:52 PM -
How to mesure ping delay in JAVA..?
By sacr83 in forum NetworkingReplies: 4Last Post: 06-15-2008, 06:37 AM -
How to write a JAVA program to mesure ping delay..?
By sacr83 in forum NetworkingReplies: 1Last Post: 02-15-2008, 04:07 PM -
ping cmd
By kishi in forum Advanced JavaReplies: 2Last Post: 11-14-2007, 03:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks