• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Java code to test network connectivity

Hi,
I want to write a java code to test the speed of network. I want to use the www.google.com as url for testing my network speed. I need to perform the following operations :
1) ping
2) Sockets
3) http
4) DNS resolution

How to i perform all these operation in java ie. how do i ping the www.google.com and get the result in java ?
Similarly i want to check how long it takes to make a sockets connection with google and how long http calls take and DNS resolution.


Thanks
0
Rohit Bajaj
Asked:
Rohit Bajaj
  • 2
  • 2
1 Solution
 
Ali Can AlbayrakSoftware EngineerCommented:
I strongly recommend you to check out ICMP4J. Do not re-invent the wheel, If you are willing to use 3rd party lib
0
 
Rohit BajajAuthor Commented:
Is there no simple way in java to create a socket and send some data and get the response just to see the rountrip time ?

I want to calculate the roundtrip time to google.
0
 
Ali Can AlbayrakSoftware EngineerCommented:
Here I posted sample code. It checks connectivity first then pings for once.
You may remove connection test part for your constraints. Because it checks connectivity over HTTP protocol.
ConnectivityTest.java
0
 
Rohit BajajAuthor Commented:
Hi
Thanks for the code.
Its good
But i nees some other way to fo for ping command in java as i will be testing this on an app on android phone.
I think in that case checking for operating system and executing the ping command wont work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now