如何从Azure云服务器ping外部IP

时间:2015-02-17 14:02:45

标签: c# .net azure azure-web-roles

我创建了一个启动命令,并已使用以下命令离开防火墙:

netsh advfirewall set allprofiles state off

我的目标是从已作为Azure云服务托管的应用程序中传达我们的服务器。

最初我想执行以下代码:

            Ping pingSender = new Ping();
            PingOptions options = new PingOptions();

            // Use the default Ttl value which is 128, 
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted. 
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120000;
            PingReply reply = pingSender.Send(this.txtAddress.Text, timeout, buffer, options);
            if (reply.Status == IPStatus.Success)
            {
                lblStatus.Text += string.Format("Address: {0} <BR />", reply.Address.ToString());
                lblStatus.Text += string.Format("RoundTrip time: {0} <BR />", reply.RoundtripTime);
                lblStatus.Text += string.Format("Time to live: {0} <BR />", reply.Options.Ttl);
                lblStatus.Text += string.Format("Don't fragment: {0} <BR />", reply.Options.DontFragment);
                lblStatus.Text += string.Format("Buffer size: {0} <BR />", reply.Buffer.Length);
            }
            else
            {
                lblStatus.Text = string.Format("Error executing ping on {0}, status : {1}", txtAddress.Text, reply.Status);
            }
        }
        catch (Exception exception)
        {
            lblStatus.Text = exception.Message;
        }

但我总能得到一个提示。没有任何成功的ping。

我只是坚持下去,任何帮助都会受到高度赞赏。 谢谢

0 个答案:

没有答案