By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

is local pc online?

P: n/a
hi,

i'm making a netowork based app. and if i have the UNC path to a local
computer is there a way i can check whether the pc is online/offline??

Gideon

Nov 14 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Gideon,

If you are planning on trying to connect to the computer once you are sure
it's online, then don't bother checking first. Just try the operation and
catch the appropriate exception that indicates the computer could not be
reached.

If you need to know whether a computer is online for informational purposes
then you have some options.

If you're sure that the computer will honor ping requests, then you can use
the Ping class in the 2.0 framework:

System.Net.Network.Ping ping
= new System.Net.NetworkInformation.Ping();

System.Net.NetworkInformation.PingReply reply
= ping.Send("Machine Name");

Console.WriteLine(reply.Status); // You want "Success"

If you're using an earlier version of the framework or if Ping won't work for
you then you can try to access a known share on the computer (you must have
the appropriate permissions to read the share):

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("\\\\Machine
Name\\C$");

Console.WriteLine(dir.Exists);

Another option is to try connecting a socket to a port that you know is open.

Realize that there is no way to be certain whether the computer is offline.
If all of these cases fail then you can just assume the computer is offline,
but it might just be that it's not responding to any of these particular
requests.

--
Dave Sexton

"giddy" <gi*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
hi,

i'm making a netowork based app. and if i have the UNC path to a local
computer is there a way i can check whether the pc is online/offline??

Gideon

Nov 14 '06 #2

P: n/a
Under .NET 2 :
System.Net.NetworkInformation.NetworkInterface.Get IsNetworkAvailable()

I'm sure there is a NetworkAvailable property on something in .NET 1 but
dont have it on my machine here so cant check for you.

Ciaran O'Donnell
"Dave Sexton" wrote:
Hi Gideon,

If you are planning on trying to connect to the computer once you are sure
it's online, then don't bother checking first. Just try the operation and
catch the appropriate exception that indicates the computer could not be
reached.

If you need to know whether a computer is online for informational purposes
then you have some options.

If you're sure that the computer will honor ping requests, then you can use
the Ping class in the 2.0 framework:

System.Net.Network.Ping ping
= new System.Net.NetworkInformation.Ping();

System.Net.NetworkInformation.PingReply reply
= ping.Send("Machine Name");

Console.WriteLine(reply.Status); // You want "Success"

If you're using an earlier version of the framework or if Ping won't work for
you then you can try to access a known share on the computer (you must have
the appropriate permissions to read the share):

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("\\\\Machine
Name\\C$");

Console.WriteLine(dir.Exists);

Another option is to try connecting a socket to a port that you know is open.

Realize that there is no way to be certain whether the computer is offline.
If all of these cases fail then you can just assume the computer is offline,
but it might just be that it's not responding to any of these particular
requests.

--
Dave Sexton

"giddy" <gi*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
hi,

i'm making a netowork based app. and if i have the UNC path to a local
computer is there a way i can check whether the pc is online/offline??

Gideon


Nov 14 '06 #3

P: n/a
Hi Ciaran,
Under .NET 2 :
System.Net.NetworkInformation.NetworkInterface.Get IsNetworkAvailable()
That may work for the local computer but it doesn't help the OP find out if a
different computer is online.
I'm sure there is a NetworkAvailable property on something in .NET 1 but
dont have it on my machine here so cant check for you.
AFAIK there is no managed equivalent in earlier framework versions.

--
Dave Sexton
Nov 14 '06 #4

P: n/a
hi ,

thanks for repying , i'm sorry i was'nt specific.. i'm using C# and
..NET 2 ....
i'm kaing a booking application for a hotel . .. and there one main pc
with a set of local pcs connected to it. The database fr the customers
is on the main pc.

basicaly i hav a listview that should have icons (pc icons) .. for
local pcs connected to it (the main pc ,lets call it server)
Now there (hopefully) will be an add function tht brings a
BrowseFrFolder dialog and allows the user to add a path. When this is
done . .the application is kinda intalled on this (client) local pc ..
..and the client then connects to the "server" for the database (this
should happen all via th UNC path) ....

Now.. .everytime the listview loads .. i wanna check whether the
ADDED pcs are offline or on and depending on that.. i want the icon to
be coloured or black and white.

I thought of doing what dave said in the first place... but was'nt
exactly sure.. .i'm new to C#...

and Dave , what do u mean by :
Dave Sexton wrote:
That may work for the local computer but it doesn't help the OP find out if a
different computer is online.
problem is i dont have a network here to test it all out i have to goto
a cyber cafe to test it.. and i cant do that often (it costs)

Thanks so much

Gideon

Nov 14 '06 #5

P: n/a
Hi Gideon,

Thanks for the background information.

<snip>
I thought of doing what dave said in the first place... but was'nt
exactly sure.. .i'm new to C#...
You should speak to the network administrator to see if there is a common port
open or share accessible on every computer on the network, or if every
computer can be configured to respond to Ping requests, for example.

There might be some other means to verify whether a computer is online or
offline within the context of a LAN. Active Directory is one LAN tool that
may be of help to you if it's already in use on the target network.

There are network protocols that can be used on a LAN to determine whether
computers are available. These protocols might provide a port that you can
query to check for connectivity.

If you can't find some common check point amongst all computers on the network
then you might find that the list you are trying to provide in your program
may not be a good representation of whether the computers are reachable or
not, and so might not be much help to the user.
and Dave , what do u mean by :
Dave Sexton wrote:
>That may work for the local computer but it doesn't help the OP find out if
a
different computer is online.
The example that was supplied can be used to determine whether there is a
network connection available on the local computer only. It won't help you to
determine the status of other computers on the network.

<snip>

--
Dave Sexton
Nov 14 '06 #6

P: n/a
HI ,

i'm making an application for a simple hotel , theres no network
administrator , and the people who are going to use my software are
simple accoutants or data enterers! lol

anyway... i' think i'll use directory.Exists() to see if the path to
the pc is valid and then chaning the lisview's picture! basically if is
it unavailiable i want to remove/Disable some of the context menu
options!

i looked a little into pinging and active directory , i might use them
later on!

thanks for your help!

Gideon

Dave Sexton wrote:
You should speak to the network administrator to see if there is a common port
open or share accessible on every computer on the network, or if every
computer can be configured to respond to Ping requests, for example.
If you can't find some common check point amongst all computers on the network
then you might find that the list you are trying to provide in your program
may not be a good representation of whether the computers are reachable or
not, and so might not be much help to the user.
Nov 17 '06 #7

P: n/a
Hi Gideon,

Are you just assuming that certain computers on the LAN might not be available
at times or are there good reasons for computer's to be offline? Are you just
concerned with network instability?

The network should probably be stable and configured properly so that all
computers are "available" at all times.

Showing the users that the computers are "available" may not help them if they
should always be available anyway. Also, it's possible that your method of
detection may show the computer as available until your application attempts
an operation that requires a connection to the remote computer, in which case
it fails and leaves the user wondering why your program said that it wouldn't
fail.

Also realize that most users would probably like to try the operation
themselves, even if your program states that the computer is probably offline.

From the information you've supplied it sounds to me like you shouldn't notify
the users of a computer's availability in the list and just assume that it
will be available at all times. If an attempted operation fails, you may want
to alert the user that the computer may be offline and to try again later.
Then, you may want to show an offline icon in the list next to the computer
name, but this shouldn't prevent your program from attempting the operation
again when the user demands it. If a subsequent attempt succeeds, you can
remove the offline icon.

This way the user decides when your program should try the operation, keeping
the user in control. And if they don't have that ability and somehow "fix"
the offline problem themselves, they'll have to wait for your program to
update the display before they can try again.

If you have a good reason for certain computers to be unavailable at times and
you think it would be better to absolutely prevent users from attempting an
operation on a remote computer that your program assumes will fail, then
you'll have to use a timer to periodically check the computer's availability
and update your display. The easiest and most light-weight approach to
determining whether a computer is online, IMO, is the Ping class. You can use
the System.Timers.Timer class in code to raise a periodic, synchronized event
at the interval you specify.

HTH

--
Dave Sexton

"giddy" <gi*******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
HI ,

i'm making an application for a simple hotel , theres no network
administrator , and the people who are going to use my software are
simple accoutants or data enterers! lol

anyway... i' think i'll use directory.Exists() to see if the path to
the pc is valid and then chaning the lisview's picture! basically if is
it unavailiable i want to remove/Disable some of the context menu
options!

i looked a little into pinging and active directory , i might use them
later on!

thanks for your help!

Gideon

Dave Sexton wrote:
>You should speak to the network administrator to see if there is a common
port
open or share accessible on every computer on the network, or if every
computer can be configured to respond to Ping requests, for example.
>If you can't find some common check point amongst all computers on the
network
then you might find that the list you are trying to provide in your program
may not be a good representation of whether the computers are reachable or
not, and so might not be much help to the user.

Nov 17 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.