azure sql server firewall settings

半城伤御伤魂 提交于 2019-12-11 04:55:56

问题


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?


回答1:


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

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.

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;
   }
}

Above information comes from here.



来源:https://stackoverflow.com/questions/48917099/azure-sql-server-firewall-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!