is local pc online?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • giddy

    is local pc online?

    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

  • Dave Sexton

    #2
    Re: is local pc online?

    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.Netw ork.Ping ping
    = new System.Net.Netw orkInformation. Ping();

    System.Net.Netw orkInformation. PingReply reply
    = ping.Send("Mach ine Name");

    Console.WriteLi ne(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.Direc toryInfo dir = new System.IO.Direc toryInfo("\\\\M achine
    Name\\C$");

    Console.WriteLi ne(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" <gidisrael@gmai l.comwrote in message
    news:1163479011 .734576.132530@ i42g2000cwa.goo glegroups.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
    >

    Comment

    • Ciaran O''Donnell

      #3
      Re: is local pc online?

      Under .NET 2 :
      System.Net.Netw orkInformation. NetworkInterfac e.GetIsNetworkA vailable()

      I'm sure there is a NetworkAvailabl e 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.Netw ork.Ping ping
      = new System.Net.Netw orkInformation. Ping();
      >
      System.Net.Netw orkInformation. PingReply reply
      = ping.Send("Mach ine Name");
      >
      Console.WriteLi ne(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.Direc toryInfo dir = new System.IO.Direc toryInfo("\\\\M achine
      Name\\C$");
      >
      Console.WriteLi ne(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" <gidisrael@gmai l.comwrote in message
      news:1163479011 .734576.132530@ i42g2000cwa.goo glegroups.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
      >
      >
      >

      Comment

      • Dave Sexton

        #4
        Re: is local pc online?

        Hi Ciaran,
        Under .NET 2 :
        System.Net.Netw orkInformation. NetworkInterfac e.GetIsNetworkA vailable()
        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 NetworkAvailabl e 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


        Comment

        • giddy

          #5
          Re: is local pc online?

          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

          Comment

          • Dave Sexton

            #6
            Re: is local pc online?

            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


            Comment

            • giddy

              #7
              Re: is local pc online?

              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.Exist s() 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.
              >

              Comment

              • Dave Sexton

                #8
                Re: is local pc online?

                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.T imer class in code to raise a periodic, synchronized event
                at the interval you specify.

                HTH

                --
                Dave Sexton

                "giddy" <gidisrael@gmai l.comwrote in message
                news:1163746429 .832539.210350@ m7g2000cwm.goog legroups.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.Exist s() 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.
                >>
                >

                Comment

                Working...