473,378 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

is system connected to the internet?

Hello to all,

Can you give me the code so that i can make sure that my system is
connected to the internet.
thank you in advance,
vishnu
Jul 17 '05 #1
3 1678
vi*************@yahoo.com (vishnu mahendra) wrote in message news:<c2*************************@posting.google.c om>...
Hello to all,

Can you give me the code so that i can make sure that my system is
connected to the internet.
thank you in advance,
vishnu


Send some client request or do Ping to one of well known servers.
Jul 17 '05 #2
You can use ping at the OS level, otherwise use code below to visit
well-known website using HTTP. If browsed, method visitWebPage() returns
true, otherwise false. False can be website is down or internet connection
unavailable.
import java.io.*;
import java.net.*;

public class UrlVisit {

/** Creates a new instance of UrlVisit */
public UrlVisit() {
}

public boolean visitWebPage(String UrlToVisit) {

boolean urlVisited = false;
try {
URL url = new URL(UrlToVisit);
URLConnection urlConnection = url.openConnection();
BufferedReader htmlPage = new BufferedReader(new
InputStreamReader(url.openStream()));

String line = "";
while((line = htmlPage.readLine()) != null) {
//do something with the html line
System.out.println(line);
}
htmlPage.close();
urlConnection = null;
urlVisited = true;
} catch(Exception e) {
urlVisited = false;
}
return urlVisited;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
UrlVisit urlVisit = new UrlVisit();
String url = null;
String commstart = " <!-- *********************** ";
String commend = " *********************** -->";
if (args[0] == null) {
url = "http://www.cnn.com";
} else {
url = args[0];
System.out.println(commstart + "Visiting "+ url + commend);
}
if (urlVisit.visitWebPage(url)) {
System.out.println(commstart + url + " visited" + commend);
} else {
System.out.println(commstart + url + " Website not found" +
commend);
}
}
}

"vishnu mahendra" <vi*************@yahoo.com> wrote in message
news:c2*************************@posting.google.co m...
Hello to all,

Can you give me the code so that i can make sure that my system is
connected to the internet.
thank you in advance,
vishnu

Jul 17 '05 #3
"JavaJunkie" <ja********@hotmail.com> wrote in message news:<_h*********************@twister.tampabay.rr. com>...
You can use ping at the OS level, otherwise use code below to visit
well-known website using HTTP. If browsed, method visitWebPage() returns
true, otherwise false. False can be website is down or internet connection
unavailable.
import java.io.*;
import java.net.*;

public class UrlVisit {

/** Creates a new instance of UrlVisit */
public UrlVisit() {
}

public boolean visitWebPage(String UrlToVisit) {

boolean urlVisited = false;
try {
URL url = new URL(UrlToVisit);
URLConnection urlConnection = url.openConnection();
BufferedReader htmlPage = new BufferedReader(new
InputStreamReader(url.openStream()));

String line = "";
while((line = htmlPage.readLine()) != null) {
//do something with the html line
System.out.println(line);
}
htmlPage.close();
urlConnection = null;
urlVisited = true;
} catch(Exception e) {
urlVisited = false;
}
return urlVisited;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
UrlVisit urlVisit = new UrlVisit();
String url = null;
String commstart = " <!-- *********************** ";
String commend = " *********************** -->";
if (args[0] == null) {
url = "http://www.cnn.com";
} else {
url = args[0];
System.out.println(commstart + "Visiting "+ url + commend);
}
if (urlVisit.visitWebPage(url)) {
System.out.println(commstart + url + " visited" + commend);
} else {
System.out.println(commstart + url + " Website not found" +
commend);
}
}
}



Thank you Mr.JavaJunkie.
I love groups.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michelle Stone | last post by:
Executing a web application (asp.net with visual c#) works at good speeds while i am not connected to the internet. but after getting connected, it becomes dreadfully slow. sometimes it even...
22
by: Zeng | last post by:
Hi, I'm running ClrProfiler for the first time to profile my web app, and it keeps getting stuck at this msg box: "Waiting for Asp.net to start common language runtime - this is the time to load...
2
by: Frances Del Rio | last post by:
I need to put content from web presentation on CD... interface contains external links (absolute urls..) is there a way to detect if user is connected to the internet (so if they're not I can pop...
3
by: leveraged | last post by:
Why can I only connect to or create a web app in VS 2003 using localhost while I am connected to the internet. I have no problems using VS 2002 but for some reason I get Microsoft Development...
3
by: Martin Ho | last post by:
My application (before is actually fully loads) should check if user is connected to internet. Is there any way to check this with certainty? Thanks a lot. Martin ----== Posted via...
3
by: geskerrett | last post by:
We have been asked to develop and application for a client that is a 'notification" system. We would like to use python, but are struggling to find the right starting point. Any suggestions, tips...
0
by: yreddy | last post by:
Hi, I got a requirement to develope an application which takes care for monitering the internet connection of a customer and it directs the customer to resolve some basic issues related to...
1
by: pavanG | last post by:
The following is the setup I have at home. The problem is I cannot ping Vista machine(192.168.2.5) from XP machine(192.168.2.2) So accessing it from Internet is Out of question My aim is to...
1
Shanaj
by: Shanaj | last post by:
Hello, Anybody knows how to get the ip address of a system connected in LAN through internet I developed a chat application which is working fine in LAN . To work in internet the server...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.