SQL Server
SQL Server
Get Local Network Adapter Addresses
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetAdaptersAddresses, which populates a JsonObject with information about local network adapters, including IPv4 addresses, IPv6 addresses, and MAC addresses.
Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.
Background. This provides a portable way to enumerate the host's network interfaces and their addresses.
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 @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @socket int
EXEC @hr = sp_OACreate 'Chilkat.Socket', @socket OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
-- IPv6 addresses, and MAC addresses.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @socket, 'GetAdaptersAddresses', @success OUT, @json
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OASetProperty @json, 'EmitCompact', 0
DECLARE @jsonStr nvarchar(4000)
EXEC sp_OAMethod @json, 'Emit', @jsonStr OUT
PRINT @jsonStr
-- JSON parsing code for this result can be generated at Chilkat's online tool:
-- https://tools.chilkat.io/jsonParse
EXEC @hr = sp_OADestroy @socket
EXEC @hr = sp_OADestroy @json
END
GO