Tuesday, February 06, 2007

Check network connection status using C#.net

Check network connection status using C#.net
Simple way to check network connection check the code below.
using System;
using System.Runtime.InteropServices;
//Creating the extern function...
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
//Creating a function that uses the API function...
public static bool IsConnectedToInternet()
{
int Desc;
return InternetGetConnectedState(out Desc, 0);
}
//Use function
if (IsConnectedToInternet())
{
MessageBox.Show("Netwok Connection Up");
}
else
{
MessageBox.Show("Sorry! Network Connection down.");
}

Ritesh Kumar Kesharwani
Cell : 91-9890901287

6 comments:

100clips said...

Thanks!

Unknown said...

thanx a lot!

Unknown said...

Hi, thanks.

I found there is a way to get a lot information about network connections with managed code.
Use the framework classes
in [System.Net.NetworkInformation]
i.e. NetworkInterface.

"The GetAllNetworkInterfaces method returns an array that contains one instance of this class for each network interface on the local computer."

Testing123 said...

hey.... i want to change connection status... i want to toggle connection , enable or disable problematically.. is that possible?

Anonymous said...

Hey,

I am regular visitor of this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]You have really contiributed very good info here riteshk.blogspot.com. Frankly speaking we really do not pay attention towards our health. In plain english I must warn you that, you are not serious about your health. Recent Research shows that nearly 50% of all U.S. grownups are either chubby or overweight[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Therefore if you're one of these citizens, you're not alone. Its true that we all can't be like Brad Pitt, Angelina Jolie, Megan Fox, and have sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? You can easily lose with with little effort. Some improvement in of daily activity can help us in losing weight quickly.

About me: I am webmaster of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health expert who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for quick weight loss.

daspeac said...

I have heard about another way of access accdb recovery. Besides, you can visit my blogs at: http://daspeac.livejournal.com/ or http://daspeac.blogspot.com/ where I’m trying to share my experience with regard to data corruption issues