You asked how to ping. Ping just tells you if there's a route to the host. It doesn't tell you the state of the services. If you want to know if a web site is serving pages, java.net.URL can be used to retrieve documents.
Aaah, thanks for clarification, Joe! I just read "ping" and didn't think about the word "website"
@sri: Note that a "ping" is working on a different network and protocol layer than "web surfing", as Joe already mentioned. With a ping you can only check if a host (IP address) is reachable on the IP layer. The WWW service in contrast uses the HTTP protocol which in turn uses the TCP protocol on port 80. Perhaps this helps you to figure out what you really want to check for!
Joined: May 23, 2008
i have used the following code.
but when i try to run this i get the following error.
The most common reason for a "connection refused" error is, if a host is reachable but it doesn't offer the service (HTTP in your case) you want to use. But in this case I don't think this is the reason unless someone has shutdown Microsoft's web servers
If a firewall would block the HTTP connections you'd usually get another error or just a timeout and it wouldn't be possible to surf on the internet from the host you're testing this program.
The only reason I can imagine is, that you are behind a proxy server! Do you try this at home or at work? Perhaps you can check if you have configured a proxy in the settings for your browser?
Joined: May 23, 2008
Thanks a lot Marco. i'm trying this at my work. if you dont mind can you please let me know how the browsers setting should be.
The problem are not the browser settings! They are surely correct as you wouldn't be able to look at this forum here if they were not
But if you're behind a proxy then you'll have to use this proxy from your Java program, too. Unfortunately I don't know ad-hoc how to use a HTTP proxy with Java. So the best would probably be for you to check with your network administrator (or someone else who is responsible for the network) if you need to use a proxy server at all and what credentials you'll have to use if it's a authentication based proxy.