473,394 Members | 1,640 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,394 software developers and data experts.

best way to determine internet connection when have only Lan ?

Hi,
I have problem to determine that I don't have any internet connection when I
have Lan Nic available that is connected to other computer and not to the
internet.

I am using the NetworkInterface.GetIsNetworkAvailable Method and then the
NetworkInterface.GetAllNetworkInterfaces Method
but it is not good enough for this situation.
my question is if the only solution will be to make some ping / connect to
server that must run all the time , and in case of exception to understand
that I don't have internet connection , or , there is some other better
method to do it ?
Thanks
Oct 14 '06 #1
6 2137
Try the Ping class
http://msdn2.microsoft.com/en-us/lib...tion.ping.aspx
(if you are using .NET 2.0).

There are many Ping imlementations for .NET 1.1 as well
http://www.google.com/search?hl=en&l...ff&q=ping+c%23

"semedao" <se*****@community.nospamwrote in message
news:eU*************@TK2MSFTNGP03.phx.gbl...
Hi,
I have problem to determine that I don't have any internet connection when
I have Lan Nic available that is connected to other computer and not to
the internet.

I am using the NetworkInterface.GetIsNetworkAvailable Method and then the
NetworkInterface.GetAllNetworkInterfaces Method
but it is not good enough for this situation.
my question is if the only solution will be to make some ping / connect to
server that must run all the time , and in case of exception to understand
that I don't have internet connection , or , there is some other better
method to do it ?
Thanks

Oct 14 '06 #2
thanks , I already know , I asked if there other way witout to make some
call over sockets to determine this
"Lebesgue" <le******@gmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Try the Ping class
http://msdn2.microsoft.com/en-us/lib...tion.ping.aspx
(if you are using .NET 2.0).

There are many Ping imlementations for .NET 1.1 as well
http://www.google.com/search?hl=en&l...ff&q=ping+c%23

"semedao" <se*****@community.nospamwrote in message
news:eU*************@TK2MSFTNGP03.phx.gbl...
>Hi,
I have problem to determine that I don't have any internet connection
when I have Lan Nic available that is connected to other computer and not
to the internet.

I am using the NetworkInterface.GetIsNetworkAvailable Method and then the
NetworkInterface.GetAllNetworkInterfaces Method
but it is not good enough for this situation.
my question is if the only solution will be to make some ping / connect
to server that must run all the time , and in case of exception to
understand that I don't have internet connection , or , there is some
other better method to do it ?
Thanks


Oct 14 '06 #3
You could just use the HttpWebRequest class and request a web page.
Something you know is always available, like www.hotmail.com, etc.
If you get a response, connection is good. If you get a bad error code,
then its bad.

I wrote my own connection monitor but it works a bit differently. It
connects to my home router and parses the web page. If it discovers
that the router page says it is "Disconnected" it sends a reboot
command. So for me, I never need to actually ping or connect to a site
outside of my lan.

Steven

Oct 15 '06 #4
Ok , but in the end , forprogram that we cannot know the end user
configuration
I must use some method of connection to external location , there is no
other way...
"Steven Nagy" <le*********@hotmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
You could just use the HttpWebRequest class and request a web page.
Something you know is always available, like www.hotmail.com, etc.
If you get a response, connection is good. If you get a bad error code,
then its bad.

I wrote my own connection monitor but it works a bit differently. It
connects to my home router and parses the web page. If it discovers
that the router page says it is "Disconnected" it sends a reboot
command. So for me, I never need to actually ping or connect to a site
outside of my lan.

Steven

Oct 15 '06 #5
Ok , but in the end , forprogram that we cannot know the end user
configuration
I must use some method of connection to external location , there is no
other way...
If you think about it, how could it work any other way? The only way to
determine connectability, is to try to access some kind of destination and
check the response. Whether you do this with ping or HttpWebRequest or any
other method is moot.

In WinInet (Win32API) there is an InternetCheckConnection function you might
want to try to PInvoke. Check msdn.microsoft.com for more info

--
Regards, Peter
Oct 15 '06 #6
Peter's right. There's not magic box called "internet" that you can
just ask if you are active.
You need a remote host to attempt to connect to. Whether that is a host
you control or not is a moot point. There are some hosts that will
never disappear that you could always use.
For example, your ISP's name servers or perhaps the domain regulator
for your country. I only suggested Hotmail because its been around a
long time and is likely to be around for a long time still.

HttpWebRequest is good because it will be more like your standard
browser's connection.
Some server's block ping for security reasons (ICMP?) but still host
pages.

Good luck,
Steven

Oct 15 '06 #7

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

Similar topics

131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
8
by: Steven Van Dyke | last post by:
Hi I need a code snippet to determine if my computer is connected to a network or not. There's probably a System.Net function for it, but I cannot find it. Thanks, Steve
3
by: danavni | last post by:
i need to build a service that will accept incoming TCP/IP connections. the service should act like a "HUB" where on one side clients connect to it and stay connected for as long as they like and...
6
by: Nate | last post by:
I am in a slight predicament trying to determine the most efficient and effective way to connect/disconnect from a database within a business object (c# dll). I'm also keeping in mind the concept...
1
by: ricolee99 | last post by:
Hi Everyone, Thanks for reading my post. Can someone please tell me if there's something in .net framework that will allow me to determine the name of the default internet connection? I have...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
3
by: Mark B | last post by:
We've got a table with around 50,000 rows. Periodically we want our Outlook Add-in (C#) app to automatically download it as XML for reference look-up use. Is the best way to use write a...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all mister, Which is THE BEST WAY IN THE WORLD AROUND for: 1. detect Network
3
by: Giampaolo Rodola' | last post by:
Hi, I'd like to know if there's a way to determine which is the best buffer size to use when you have to send() and recv() some data over the network. I have an FTP server application which, on...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.