我尚未找到任何有关如何预测 Azure 将您视为的 IP 地址的文档。
这是我所指的 IP(红色):
我正在尝试以编程方式实现“当前客户端 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/