PC Review


Reply
Thread Tools Rate Thread

Best way detect Network and Internet Connection

 
 
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#, how convert to VB.NET



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
www.kiquenet.com/churrosoft
http://www.setbb.com/putainformatica...opic.php?p=843
www.trabajobasura.com/solusoft

 
Reply With Quote
 
 
 
 
Teme64
Guest
Posts: n/a
 
      29th Oct 2008
Alhambra Eidos Desarrollo wrote:
> 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#, how convert to VB.NET
>
>
>
> 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.");
> }
>

Converted with http://www.developerfusion.com/tools.../csharp-to-vb/

Dim req As HttpWebRequest
Dim resp As HttpWebResponse
Try
req = DirectCast(WebRequest.Create("http://www.google.com"), HttpWebRequest)
resp = DirectCast(req.GetResponse(), HttpWebResponse)

If resp.StatusCode.ToString().Equals("OK") Then
Console.WriteLine("its connected.")
Else
Console.WriteLine("its not connected.")
End If
Catch exc As Exception
Console.WriteLine("its not connected.")
End Try

--

Teme64 @ http://windevblog.blogspot.com
 
Reply With Quote
 
Alhambra Eidos Desarrollo
Guest
Posts: n/a
 
      30th Oct 2008


And which is the best way to do this:

detect Network

detect Internet Connection

Thanks !!!
 
Reply With Quote
 
G.S.
Guest
Posts: n/a
 
      30th Oct 2008
On Oct 30, 3:31*am, Alhambra Eidos Desarrollo
<AlhambraEidosDesarro...@discussions.microsoft.com> wrote:
> And which is the best way to do this:
>
> detect Network
>
> detect Internet Connection
>
> Thanks !!!


Sorry - I cannot answer your direct question, but I will be facing
your issue in a few weeks. My intention was to dig deep into how
Microsoft deal with it in the impelementation of their Disconnected
Service Agent Application block... There's plenty info about it on the
net.. here's an example:
http://www.codeplex.com/smartclient/...ThreadId=15938
Maybe you can integrate that block instead...
 
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
Detect if Network and Internet Connection, the best way !!! Alhambra Eidos Desarrollo Microsoft C# .NET 0 29th Oct 2008 12:27 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 04:28 AM.