Resolve hostnames with t-sql

后端 未结 2 1306
面向向阳花
面向向阳花 2020-12-22 04:07

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.

eg. If i have the

相关标签:
2条回答
  • 2020-12-22 04:36

    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.

    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().

    0 讨论(0)
  • 2020-12-22 05:01

    SQL Server may block access to procedure 'sys.xp_cmdshell' as part of the security configuration. As a system administrator you can enable the use of 'xp_cmdshell' as follows:

    -- 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
    
    0 讨论(0)
提交回复
热议问题