如何解析t-sql中的主機名稱? 2000兼容的方法是優選的。雖然2005/2008年的一些工作也會有所幫助。使用t-sql解析主機名稱
例如。如果我有主機名stackoverflow.com我想返回69.59.196.211
如何解析t-sql中的主機名稱? 2000兼容的方法是優選的。雖然2005/2008年的一些工作也會有所幫助。使用t-sql解析主機名稱
例如。如果我有主機名stackoverflow.com我想返回69.59.196.211
嗯,我想你可以使用xp_cmdshell執行nslookup並解析結果。不過,對於SQL Server來說,這似乎是一件非常尷尬的事情。
exec master..xp_cmdshell 'nslookup intel.com'
..然後你可能會想的東西,在一個臨時表,並通過結果走。
如果您可以訪問SQL Server 2005或2008,則可以使用.NET構建存儲過程或函數,並對Dns.GetHostAddresses()
進行簡單調用。
作爲安全配置的一部分,SQL Server可能會阻止對過程「sys.xp_cmdshell」的訪問。作爲一個系統管理員可以允許使用「的xp_cmdshell」如下:
-- Allow advanced options.
EXEC sp_configure 'show advanced options', 1;
GO
-- Update the currently configured value for advanced options.
RECONFIGURE;
GO
-- Then, enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
GO
-- Update the currently configured value for this feature.
RECONFIGURE;
GO
-- Then you can go ahead and run ...
exec master..xp_cmdshell 'nslookup microsoft.com'
GO
我不知道這將是一個數據庫來進行適當的功能。另外,您是否知道單個主機名可能會解析爲多個IP地址? – 2009-06-09 00:43:30
是啊,我知道有一些事情,如循環賽的DNS會給你不同的IP,但我不必處理在工作環境中的那個。 – 2009-06-09 00:50:05