Azure SQL Server防火墙设置 [英] azure sql server firewall settings

查看:159
本文介绍了Azure SQL Server防火墙设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to find my computer's external IP address for azure sql server firewall settings? It is different from the one I get from Ipconfig command(IPv4). I can see a specific IP address on the azure portal but want to know if/how I can see it from my machine?

推荐答案

有一个"AutoDetectClientIP"管理API调用,可将现有的防火墙例外更新为呼叫者的IP地址.

There is a "AutoDetectClientIP" Management API call that updates an existing Firewall Exception to the caller's IP address.

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

But you need access to a Management Certificate that is valid for the given subscription, the subscription ID, the name of the SQL Azure Server and the name of the Firewall Exception.

下面如何使用该API.

Below how you can use that 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;
   }
}

以上信息来自此处.

这篇关于Azure SQL Server防火墙设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆