473,586 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2221
"Steven Van Dyke" <sv******@rft.c om> wrote in message
news:ut******** ******@TK2MSFTN GP09.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***********@s urfcontrol.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******** ******@TK2MSFTN GP09.phx.gbl...
"Steven Van Dyke" <sv******@rft.c om> wrote in message
news:ut******** ******@TK2MSFTN GP09.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***********@s urfcontrol.com

Nov 17 '05 #3
"Steven Van Dyke" <sv******@rft.c om> wrote in message
news:uz******** *****@tk2msftng p13.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***********@s urfcontrol.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******** ********@TK2MSF TNGP12.phx.gbl. ..
"Steven Van Dyke" <sv******@rft.c om> wrote in message
news:uz******** *****@tk2msftng p13.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***********@s urfcontrol.com

Nov 17 '05 #5
"Steven Van Dyke" <sv******@rft.c om> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
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***********@s urfcontrol.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("wini net.dll")]
private extern static bool InternetGetConn ectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConn ectedState( 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****@aspital ia.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("wini net.dll")]
private extern static bool InternetGetConn ectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConn ectedState( 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****@aspital ia.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("wini net.dll")]
private extern static bool InternetGetConn ectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConn ectedState( 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
1937
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: shutil.copy2(newArrivalsDir+'/'+movie,archivesDir) thumb = string.replace(movie,'.avi','.jpg') shutil.copy2(newArrivalsDir+'/tn/'+thumb,archivesDir+'/tn/')
8
4798
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 windows displays). any ideas?? THanks
7
12403
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 database on the server, otherwise I want to use a cache on the laptop. I do know the address of a server on the LAN. The only way I can see is...
40
2945
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 front end open at the first form) and even though this links to the back-end files, there are no ldb files created. This is so I know when it is...
8
10375
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 is on. I was thinking I could make a HTTP Request to a server which displays your IP address as they see it and scrape it out of the response but...
25
14484
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
3400
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 determine the IP address of the network load balanced machine that the message is generated from? So, in essence, I have server1, server2 and server3...
1
20589
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 I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call...
3
13218
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 data channel, uses 8192 bytes as buffer for both incoming and outgoing data. Some time ago I received a report from a guy who stated that changing...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.