Skip navigation

Performing a Reverse DNS Lookup

Is it possible to perform a reverse DNS lookup in a stored procedure or from a SQL Server Agent job?

You can use a simple technique that relies on xp_cmdshell to perform a reverse DNS lookup. Xp_cmdshell can be a security risk if not managed properly, but it can also be a powerful tool for doing specialized tasks in a controlled manner from T-SQL. For example, you can use the following code, then manipulate the output any way you need to.

DECLARE @OSCmd varchar(8000)
DECLARE @DomainName varchar(8000)
SET @DomainName  = 'www.solidqualitylearning.com'
SET @OSCmd = 'NSLOOKUP ' + @DomainName
EXEC master.dbo.xp_cmdshell @OSCmd
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish