Code:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net.Sockets;

namespace CSharpCheckingOnlineAvailabilityIPPort

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void btn_CheckServer_Click(object sender, EventArgs e)

        {

            TcpClient logonServer = new TcpClient();

            try

            {

                logonServer.Connect("127.0.0.1", 80); //this is just your loop back and checking to see if port 80 is open swap out for whatever you want

            }

            catch (Exception ex)

            {

         

            }

            if (logonServer.Connected)

                this.Text = "Connected";

            else

                this.Text = "Not connected";

            logonServer.Close();

        }

    }

}
Source Code