views:

345

answers:

1

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 hostname stackoverflow.com i want to return 69.59.196.211

+3  A: 

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

Michael Petrotta
I'm lazy here, got some sample code?
Nick Kavadias
Completely untested, from the Forum That Shall Not Be Named:CREATE Procedure xp_Nslookup@ip varchar(17)as declare @cmd varchar(255)/*set @ip = '192.168.100.1'*/set @cmd = 'For /F "skip=2 tokens=1,2" %i in (''c:\winnt\system32\nslookup.exe '+@IP+''') do @echo '+@IP+'^|%i^|%j^|'+ convert(varchar(20),getdate())insert into Nslookup exec master..xp_cmdshell @cmddelete Nslookup where Data is nullGO
Michael Petrotta