472,956 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to: Determine if you have a Network Connection???

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
Nov 17 '05 #1
8 2193
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
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.


You probably want to get a bit more specific. For instance, do you care
_which_ network it's connected to? Would a home network with just one
printer on it be as useful to you as being connected to the Internet?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #2
This is an app for work. It needs to gain access to other computers on the
network. It does NOT need to get on the Internet. Basically, If I'm
connected to a network, I populate a combo box with all of the machine names
on the network. If I'm not connected, I just put the local machine name in
the combo box. My only issue is, how do I easily determine if I have a
connection or not?

Steve

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
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.


You probably want to get a bit more specific. For instance, do you care
_which_ network it's connected to? Would a home network with just one
printer on it be as useful to you as being connected to the Internet?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #3
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
This is an app for work. It needs to gain access to other computers on the
network. It does NOT need to get on the Internet. Basically, If I'm
connected to a network, I populate a combo box with all of the machine names on the network. If I'm not connected, I just put the local machine name in
the combo box. My only issue is, how do I easily determine if I have a
connection or not?


I think I'd just try it and find out. If it fails, just put the local
machine name in the box. If it succeeds, put all of them there. This will
also take care of the case where you're connected to the network, but some
other problem prevents you from getting the list of machine names.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #4
Hi,

Thanks for your response. I'm using the API call NetServerEnum. When my
network cable is plugged in, it succeeds, and returns all of my network
computer names. When the cable is disconnected, it still succeeds, returning
just 1 computer name "sv-file". I was hoping it would either fail, or return
zero entries. I didn't think it would be a good idea to say "if (count > 1)
then connected..."

I'm not sure why "sv-file" still appears in the list. Any thoughts on the
best solution?

Steve

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
This is an app for work. It needs to gain access to other computers on the network. It does NOT need to get on the Internet. Basically, If I'm
connected to a network, I populate a combo box with all of the machine

names
on the network. If I'm not connected, I just put the local machine name in the combo box. My only issue is, how do I easily determine if I have a
connection or not?


I think I'd just try it and find out. If it fails, just put the local
machine name in the box. If it succeeds, put all of them there. This will
also take care of the case where you're connected to the network, but some
other problem prevents you from getting the list of machine names.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #5
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Hi,

Thanks for your response. I'm using the API call NetServerEnum. When my
network cable is plugged in, it succeeds, and returns all of my network
computer names. When the cable is disconnected, it still succeeds, returning just 1 computer name "sv-file". I was hoping it would either fail, or return zero entries. I didn't think it would be a good idea to say "if (count > 1) then connected..."

I'm not sure why "sv-file" still appears in the list. Any thoughts on the
best solution?


Is sv-file your computer? If not, then I have no idea. Is it the domain
controller or something? With the cable disconnected, are you able to do
"NET VIEW \\SV-FILE"? How about when it's connected?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #6
> 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


Read this document:
http://www.mentalis.org/apilist/Inte...tedState.shtml

And read this example (author Cangiano):

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class ConnectionState
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConnectedState( out Descrizione, 0 ) ;}
}

Bye
--
AZ
Nov 17 '05 #7
Thanks for your response. I tried your code snippet. It seems to return the
same Descrizione value of 18 whether my network cable is connected or not.
So, it doesn't seem to solve my problem.

Steve
"Andrea Zani" <an****@aspitalia.com> wrote in message
news:bj************@ID-192116.news.uni-berlin.de...
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


Read this document:
http://www.mentalis.org/apilist/Inte...tedState.shtml

And read this example (author Cangiano):

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class ConnectionState
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConnectedState( out Descrizione, 0 ) ;}
}

Bye
--
AZ

Nov 17 '05 #8
Hi,

I tried your solution. It seems to return the same Descrizione value of 18
whether my network card cable is connected or not. So, this doesn't help my
problem.

There must be some simple function that can determine if there is a live
network cable plugged into my network card. Any other suggestions?

Steve

"Andrea Zani" <an****@aspitalia.com> wrote in message
news:bj************@ID-192116.news.uni-berlin.de...
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


Read this document:
http://www.mentalis.org/apilist/Inte...tedState.shtml

And read this example (author Cangiano):

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class ConnectionState
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConnectedState( out Descrizione, 0 ) ;}
}

Bye
--
AZ

Nov 17 '05 #9

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

Similar topics

7
by: Kamus of Kadizhar | last post by:
Thanks to everyone on this list. I now have a functioning piece of python code!! :-)) Now I'm trying to clean it up. I have the same (or similar) lines repeated several times: ...
8
by: codecraig | last post by:
hi, how can i use python to figure the ip address of the machine which the python script is running on? I dont mean like 127.0.0.1....but i want the external IP address (such as ipconfig on...
7
by: Chuck | last post by:
I am developing an application for use on laptop computers. I need to be able to programmatically determine if the laptop is connected to the network. If the connection exists I want to use the...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
8
by: MrNobody | last post by:
I need to find out the IP address of my local network on the WAN. There is alot of information on getting my local machine IP address but I can't find anything for getting the IP address my network...
25
by: _DD | last post by:
I'd like to include a 'Test Connection' button in an app, for testing validity of a SQL connection string. I'd prefer to keep the timeout low. What is the conventional way of doing this?
6
by: BA | last post by:
Hi Everyone, I have an application that sits behind a server farm, the application needs to pass its NLB IP address in the message that it sends to another service. From C# code, how can I...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.