SQL Server
SQL Server
Resolve a Hostname to an IP Address
See more Socket/SSL/TLS Examples
Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.
Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @socket int
EXEC @hr = sp_OACreate 'Chilkat.Socket', @socket OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
DECLARE @ipAddress nvarchar(4000)
EXEC sp_OAMethod @socket, 'DnsLookup', @ipAddress OUT, 'example.com', 5000
EXEC sp_OAGetProperty @socket, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
RETURN
END
PRINT 'Resolved IP address: ' + @ipAddress
EXEC @hr = sp_OADestroy @socket
END
GO