【问题标题】:azure sql server firewall settingsazure sql server 防火墙设置
【发布时间】:2018-02-21 23:13:13
【问题描述】:

如何找到我的计算机的外部 IP 地址以进行 azure sql server 防火墙设置?它与我从 Ipconfig 命令(IPv4)获得的不同。我可以在 azure 门户上看到特定的 IP 地址,但想知道是否/如何从我的机器上看到它?

【问题讨论】:

  • 只需进行网络搜索以确定您的外部 IP 地址。有很多网站可以为您提供这些信息。也就是说:这对于 StackOverflow 来说是题外话。更适合超级用户。
  • @DavidMakogon 我尝试了其中的几个(例如:whatismyip.host)。他们没有列出 azure 门户列出的 IP...

标签: azure-sql-database


【解决方案1】:

有一个“AutoDetectClientIP”管理 API 调用将现有的防火墙异常更新为调用者的 IP 地址。

但您需要访问对给定订阅有效的管理证书、订阅 ID、SQL Azure 服务器的名称和防火墙例外的名称。

下面介绍如何使用该 API。

public static bool SetFirewallRuleAutoDetect(string certFilename, string certPassword, string subscriptionId, string serverName, string ruleName)
{
    try
    {
       string url = string.Format("https://management.database.windows.net:8443/{0}/servers/{1}/firewallrules/{2}?op=AutoDetectClientIP",
                                  subscriptionId, 
                                  serverName, 
                                  ruleName);

       HttpWebRequest webRequest = HttpWebRequest.Create(url) as HttpWebRequest;

       webRequest.ClientCertificates.Add(new X509Certificate2(certFilename, certPassword));
       webRequest.Method = "POST";
       webRequest.Headers["x-ms-version"] = "1.0";
       webRequest.ContentLength = 0;

       // call the management api
       // there is no information contained in the response, it only needs to work
       using (WebResponse response = webRequest.GetResponse())
       using (Stream stream = webResponse.GetResponseStream())
       using (StreamReader sr = new StreamReader(stream))
       {
           Console.WriteLine(sr.ReadToEnd());
       }

       // the firewall was successfully updated
       return true;
   }
   catch
   {
       // there was an error and the firewall possibly not updated
       return false;
   }
}

以上信息来自here。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-18
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多