powershell - Azure 客户端 IP 地址

标签 powershell azure

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

这是我所指的 IP(红色):

Windows Azure Server SQL database server configuration panel

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

最佳答案

以下内容对我有用:有一个“AutoDetectClientIP”管理 API 调用,可将现有的防火墙异常(exception)更新为调用者的 IP 地址。

但是您需要访问对给定订阅有效的管理证书、订阅 ID、SQL Azure 服务器名称和防火墙异常(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;
   }
}

关于powershell - Azure 客户端 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14816319/

相关文章:

Azure AD - 拉取所有部门的图形 API 请求

powershell - Invoke-WebRequest 在 Azure 自动化中不起作用

powershell - 收集 IP 地址信息

powershell - 通过 Azure AD v2 powershell 删除多个许可证

asp.net - 为什么在 WebAPI 中访问 session 状态和 HttpContext 被认为是糟糕的设计?

azure Blob MD5 校验和与本地 MD5 校验和不匹配

json - 使用 GitHub api 调用 WebRequest 失败 - "Problems parsing json"

powershell - 为什么在存储安全字符串时会这样做?

c# - 可以添加到 Azure 队列的 Base64 编码字符串的最大长度是多少?

azure - 向 Azure IoT 中心中的特定消费者组发送 D2C 消息?