简体   繁体   English

我怎么知道数据库的实际地理位置?

[英]How can i know the actual geographical location of a database?

I am tasked to get the location where our SQL Server database is geographically located via C# code because it may vary time to time due to frequent relocation of our database to protect it from physical and cyber harm. 我的任务是通过C#代码获取我们的SQL Server数据库在地理位置所在的位置,因为由于我们的数据库经常重新定位以保护它免受物理和网络伤害,它可能会不时变化。 Is this possible or another dream of my boss thanks in advance. 这是可能的还是我的老板的另一个梦想提前感谢。

1 - Buy somethihng like this. 1 - 买这样的东西。 It's a UPS GPS receiver. 这是一个UPS GPS接收器。

2 - Connect it to the server machine. 2 - 将其连接到服务器计算机。

3 - Write a batch or shell script that will call the GPS software and return the current position. 3 - 编写将调用GPS软件并返回当前位置的批处理或shell脚本。

4 - Use xp_cmdshell to call this script and return the current position via SQL Server query. 4 - 使用xp_cmdshell调用此脚本并通过SQL Server查询返回当前位置。

Buy an iPhone/Android phone and have it sellotaped to the top of the machine that has the database on it. 购买一部iPhone / Android手机,并将其销售到拥有数据库的机器顶部。 Write a quick app to have it look at the GPS API and post it's position to the database the phone is connected on using some kind of JSON/SOAP API over HTTPS (for security purposes). 编写一个快速应用程序,让它看一下GPS API并将其位置发布到手机上使用某种JSON / SOAP API通过HTTPS连接的数据库(出于安全目的)。

You can then access the GPS information from where you are using C#. 然后,您可以从使用C#的位置访问GPS信息。

Edit 编辑

Working with the GPS on Mono/iPhone: http://drdobbs.com/mobility/222600599 在Mono / iPhone上使用GPS: http//drdobbs.com/mobility/222600599

Example code, GPS on Mono/Android: https://github.com/gshackles/Sample-Projects/blob/master/MonoDroid/MonoDroidSamples/MonoDroidSamples/DemoActivities/LocationDemo/LocationActivity.cs 示例代码,Mono / Android上的GPS: https//github.com/gshackles/Sample-Projects/blob/master/MonoDroid/MonoDroidSamples/MonoDroidSamples/DemoActivities/LocationDemo/LocationActivity.cs

The simplest solution is to do a DNS lookup, then use an IP location service as Cody suggested. 最简单的解决方案是进行DNS查找,然后使用Cody建议的IP位置服务。 Try this: 试试这个:

var foo = Dns.GetHostEntry("database.windows.net");

Once you've got your IP address, you'll need to load something like http://www.iplocationfinder.com/65.55.23.107 using an HttpWebRequest, unless you want to pay for an IP location database. 获得IP地址后,除非要支付IP位置数据库,否则需要使用HttpWebRequest加载类似http://www.iplocationfinder.com/65.55.23.107的内容 Once you've got the response to the HttpWebRequest, you can use a regular expression to parse the location name, or latitude and longitude if you need that instead. 获得HttpWebRequest的响应后,您可以使用正则表达式来解析位置名称,或者根据需要解析纬度和经度。

Do you have so many servers which are moved around overnight in your company or is this for a cloud db setup? 您是否有这么多服务器在您公司的夜间移动,或者这是用于云数据库设置? the IP address is probably a basic inaccurate-better than nothing starting point. IP地址可能是一个基本的不准确 - 比起点更好。

As Davide Piras mentioned you can use for example this site : http://ip-lookup.net/ to trace the IP Address of you're DB Server and you can grab the Output maybe using Regular Expresion's or http://htmlagilitypack.codeplex.com/ . 正如达维德Piras酒店指出,可以使用例如这个网站: http://ip-lookup.net/追查IP地址你是DB Server和你也许可以用正规表示法的或者抢输出的http:// htmlagilitypack。 codeplex.com/

Bu that works only if you can get you're DB Server IP Address ,which i think shouldn't be an Issue because you need the IP for the Connection String . Bu只有在你能获得数据库服务器IP地址时才有效,我认为这不应该是一个问题,因为你需要连接字符串的IP。

To achieve that use a WebBrowser Control ,do webbrowser1.navigate("http://ip-lookup.net/"); 要实现这一点,请使用WebBrowser控件,执行webbrowser1.navigate("http://ip-lookup.net/"); than : 比:

HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("input");
            foreach (HtmlElement el in elc)
            {
                if (el.GetAttribute("type").Equals("text") && el.GetAttribute("name").Equals("ip"))
                {
                    el.InnerText = "Server IP";
                }
            }

next : 下一个 :

HtmlElement form = webBrowser1.Document.GetElementById("form_single_IP");
            if (form != null)
                form.InvokeMember("submit");
             //Submit the form

and try to filter the output because im not very good using Regex .You can capture the Output by using webbrowser1.DocumentText; 并尝试过滤输出,因为使用正则表达式我不是很好。您可以使用webbrowser1.DocumentText;捕获输出webbrowser1.DocumentText;

Why not use the database to tell you the location? 为什么不使用数据库告诉你位置? To clarify what I mean: 澄清我的意思:

Using SQL CLR Stored Procedure To Track IP Address - but make the CLR sproc return the ipaddress of the server its hosted on. 使用SQL CLR存储过程跟踪IP地址 - 但使CLR sproc返回其托管的服务器的ipaddress。

I saw the azure connection string you mentioned to Cody and thought these would be a handy links: http://blogs.msdn.com/b/windowsazure/archive/2011/07/06/windows-azure-deployments-and-the-virtual-ip-address.aspx 我看到你提到的Cody的天蓝色连接字符串,并认为这些是一个方便的链接: http//blogs.msdn.com/b/windowsazure/archive/2011/07/06/windows-azure-deployments-and-the -虚拟-IP-address.aspx

Get Azure public IP address from deployed app 从已部署的应用获取Azure公共IP地址

Determining the time zone is probably the best you can do from SQL Server, but that could be enough for you based on your description. 确定时区可能是您从SQL Server可以做的最好的时间,但根据您的描述,这对您来说已经足够了。 You can use this query to get the GMT offset of the time zone where the server is located: 您可以使用此查询来获取服务器所在时区的GMT偏移量:

SELECT DATEDIFF(hh, GETUTCDATE(), GETDATE()) AS ServerTimeZone

From this result, you can easily add some logic to return the time zone abbreviation, ie EST , CST , etc. I know this isn't much, but hopefully it helps. 从这个结果中,您可以轻松添加一些逻辑来返回时区缩写,即ESTCST等。我知道这并不多,但希望它有所帮助。

If someone already physically moves the server, why not write some script that writes the corresponding location to DB? 如果有人已经在物理上移动服务器,为什么不写一些将相应位置写入DB的脚本? When the machine starts up, auto-start that tool and have the "mover" select a location. 当机器启动时,自动启动该工具并让“移动器”选择一个位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何知道 PostgrSQL 中数据库的大小 - How can I know the size of a database in PostgrSQL 我怎么知道数据库中是否存在这样的值? (ADO.NET) - How can I know if such value exists in database? (ADO.NET) 我如何知道分配给线程的实际时间片? - How do I get to know the actual time slice given to a thread? 如何将实际控件存储在列表中? - How can I store the actual control in a list? 如何将字符串具体化为实际类型? - How can I materialize a string to the actual type? 我可以从数据库读取图像,但是不知道如何在asp.net页面中查看图像? - I can read image from database but I don't know how I can view image in asp.net page? 如何知道实际单元格中是否有边框顶部 - How to know if the actual cell has border top in 如何使用 c# 运行 exe 文件(我不能使用 Process.Start() 因为我不知道 exe 文件的位置) - How can I run an exe file with c# (I can't use Process.Start() because I don't know the exe file's location) 如何比较两个 IEnumerable<T> 在 C# 中,如果我不知道实际的对象类型? - How to compare two IEnumerable<T> in C# if I don't know the actual object type? 根据地理位置限制访问网站 - Restrict access to Website based on Geographical location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM