PC Review


Reply
Thread Tools Rate Thread

Detect if Network and Internet Connection, the best way !!!

 
 
Alhambra Eidos Desarrollo
Guest
Posts: n/a
 
      29th Oct 2008

Hi all mister,



Which is THE BEST WAY IN THE WORLD AROUND for:



1. detect Network



2. detect Internet Connection is working...


which is the best way in the world and good practice recommended by MVPs
Microsoft ?

Thanks in advanced..



code below...but which is the best code ???



NetworkInterface.GetIsNetworkAvailable()



private static int ERROR_SUCCESS = 0;
public static bool IsInternetConnected() {
long dwConnectionFlags = 0;
if (!InternetGetConnectedState(dwConnectionFlags, 0))
return false;

if(InternetAttemptConnect(0) != ERROR_SUCCESS)
return false;

return true;
}


[DllImport("wininet.dll", SetLastError=true)]
public static extern int InternetAttemptConnect(uint res);


[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetGetConnectedState(long flags,long
reserved);



Correct translation below.

[DllImport("wininet.dll", SetLastError=true)] public static extern bool
InternetGetConnectedState(out int flags,int reserved);


I found code in C#,



HttpWebRequest req;
HttpWebResponse resp;
try
{
req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
resp = (HttpWebResponse)req.GetResponse();

if(resp.StatusCode.ToString().Equals("OK"))
{
Console.WriteLine("its connected.");
}
else
{
Console.WriteLine("its not connected.");
}
}
catch(Exception exc)
{
Console.WriteLine("its not connected.");
}





--------------------------------------------------------------------------------
http://www.alhambra-eidos.es/web2005/index.html
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.com/churrosoft
http://www.setbb.com/putainformatica...opic.php?p=843
www.trabajobasura.com/solusoft

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way detect Network and Internet Connection Alhambra Eidos Desarrollo Microsoft C# .NET 3 30th Oct 2008 01:56 PM
Can't detect internet connection !!!! =?Utf-8?B?cnlzbmlrag==?= Spyware Announcements 8 11th Dec 2005 06:05 PM
Cannot detect internet connection Kodalika Spyware Discussion 8 1st Sep 2005 05:17 AM
Detect ActiveSync connection or internet connection Mike Microsoft Dot NET Compact Framework 1 4th Jun 2004 10:41 PM
Cannot Detect Network at Certain Startups . . Need to reboot frequently to get an Internet connection. Brian Oakes [MSFT] Microsoft Windows 2000 Networking 1 15th Aug 2003 05:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:44 AM.