473,396 Members | 2,011 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,396 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 2213
"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...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.