Test whether a computer is alive or not.

CodeKeep C# Feed Maggio 7th, 2008

Description: Test whether a computer is alive or not.

do it by ping.

Link: http://www.codekeep.net/snippets/85d2d68d-4cf1-47b2-83a5-44ae2efb5e91.aspx

//Check whether the node is alive or not. If alive, return the IP.
        protected static string CheckNodeConnectivity (string hostName)
        {
            bool nodeIsAlive=false;
            string nodeIP = string.Empty;
            using (Ping ping=new Ping() )
            {
                try
                {
                    PingReply reply = ping.Send(hostName, 600); //600 ms
                    if (reply.Status ==IPStatus .Success )
                    {
                        nodeIsAlive = true;
                        nodeIP = reply.Address.ToString();
                    }
                }
                catch (Exception err)
                {
                   // Console.WriteLine("Error has occurred in method CheckNodeConnectivity: " +err.Message );
                }

            }
            return nodeIP;
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments are closed.

Trackback URI |