Azure客户端IP地址 [英] Azure client IP address

查看:75
本文介绍了Azure客户端IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何有关如何预测Azure将您视为IP地址的文档.

I haven't been able to find any documentation on how to predict the IP address that Azure sees you as.

这是我指的IP,用红色表示:

Here's the IP that I'm referring to, in red:

我正在尝试实现以编程方式添加到允许的IP地址的当前客户端IP地址xxx.xxx.xxx.xxx.

I'm trying to implement CURRENT CLIENT IP ADDRESS xxx.xxx.xxx.xxx ADD TO ALLOWED IP ADDRESSES programmatically.

推荐答案

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

Here is what worked for me: 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.

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客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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