如何找到用于Azure SQL Server防火墙设置的计算机外部IP地址?它与我从ipconfig命令(IPv4(获得的不同。我可以在Azure门户上看到一个特定的IP地址,但想知道/我如何从计算机看到它?
有一个" autodetectclientip"管理API调用,将现有防火墙异常更新为呼叫者的IP地址。
但是,您需要访问对给定订阅,订阅ID,SQL Azure服务器的名称和防火墙异常名称的管理证书。
在下面如何使用该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;
}
}
上面的信息来自这里。