Azure客户端IP地址
问题描述:
我一直无法找到有关如何预测Azure认为您的IP地址的任何文档。Azure客户端IP地址
下面是我指的是,在红色IP:我想实现当前客户端IP地址xxx.xxx.xxx.xxx加入编程允许的IP地址
。
答
以下是我的工作原理:有一个“AutoDetectClientIP”管理API调用,可将现有防火墙异常更新为调用者的IP地址。
但是您需要访问对给定订阅,订阅ID,SQL Azure服务器名称和防火墙例外名称有效的管理证书。
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;
}
}
答
您的IP地址取决于您所在网络的NAT,除非您来自拥有固定公用IP地址的计算机。除非您的客户端计算机从同一个网络连接,并且您已详细了解网络,否则您不可能可靠地预测客户端IP地址。唯一的解决方法是添加一个范围从86.0.0.0到86.255.255.255,并希望它涵盖了你所连接的网络 - 但是大量的“不受欢迎的人”也会在这个范围内登陆。
客户端IP地址功能不应用于除直接管理访问之外的任何操作,可以根据需要随时手动设置。它也可以使用本地防火墙规则锁定,通过将端口1433的访问限制在特定的本地网络机器上。任何更多的一般访问应限制为各种服务 - 例如OData风格,mobile services或使用某种port bridge,这可以通过VPN,VM和其他IaaS服务来实现。
我建议您先强烈思考您的使用案例 - 直接SQL访问不是云计算的可行模式。存在更快,更安全,更易于管理的许多替代方案。另外,至少你正在进入一个痛苦的世界,试图让这些人在安全方面为他们的防火墙找出SQL端口的漏洞。
我刚才看到你用“powershell”标记了这个问题,我认为这个想法也可能转移到了powershell脚本中。 – Nico 2013-02-11 17:06:43