2016-04-05

Cannot ping Azure VM

They say it is a security feature. They say it is possible to use ping only from inside virtual network, but not from the internet. They say you should use port pings instead of ICMP to test Azure VM connectivity. As there are many tools like PsPing or Telnet available to check connection from command line I needed C# function to perform the task.

It turns out that this simple method does the job:

public static bool PingHost(string _HostURI, int _PortNumber)
{
    try
    {
        TcpClient client = new TcpClient(_HostURI, _PortNumber);
        return true;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error pinging host:'" + _HostURI + ":" + _PortNumber.ToString() + "'");
        return false;
    }
}

No comments:

Post a Comment