使用 t-sql 解析主机名 [英] Resolve hostnames with t-sql
问题描述
如何在 t-sql 中解析主机名?2000 兼容的方法是首选.尽管适用于 2005/2008 的东西也会有所帮助.
How can i resolve a hostname in t-sql? a 2000 compatible method is preferred. Although something that works on 2005/2008 would also be helpful.
例如.如果我有主机名 stackoverflow.com 我想返回 69.59.196.211
eg. If i have the hostname stackoverflow.com i want to return 69.59.196.211
推荐答案
好吧,我想你可以使用 xp_cmdshell 执行 nslookup 并解析结果.不过,对于 SQL Server 来说,这似乎是一件非常尴尬的事情.
Well, I suppose you could use xp_cmdshell to execute nslookup and parse the results. Seems like a really awkward thing for SQL Server to be doing, though.
exec master..xp_cmdshell 'nslookup intel.com'
...那么您可能希望将其放入临时表中并查看结果.
.. then you'll probably want to stuff that in a temp table and walk through the results.
如果您可以访问 SQL Server 2005 或 2008,也可以在 .NET 中构建存储过程或函数,然后简单调用 Dns.GetHostAddresses()
.
You could also, if you can get access to SQL Server 2005 or 2008, build a stored procedure or function in .NET and do a simple call to Dns.GetHostAddresses()
.
这篇关于使用 t-sql 解析主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!