首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >azure sql server防火墙设置

azure sql server防火墙设置
EN

Stack Overflow用户
提问于 2018-02-22 07:13:14
回答 1查看 87关注 0票数 1

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-22 11:28:02

有一个"AutoDetectClientIP“管理应用编程接口调用,它将现有防火墙例外更新为调用者的IP地址。

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

下面介绍如何使用该API。

代码语言:javascript
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48917099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档