[SQL Server] Trouver l'adresse Ip d'un serveur SQL Server
BEGIN
DECLARE @ipLine VARCHAR(200)
DECLARE @pos INT
DECLARE @ip VARCHAR(40)
SET NOCOUNT ON
SET @ip = NULL
CREATE TABLE #temp
(
ipLine VARCHAR(200)
)
INSERT #temp EXEC master..xp_cmdshell'ipconfig'
SELECT @ipLine = ipLine
FROM #temp
WHERE UPPER(ipLine) LIKE '%IP ADDRESS%' OR UPPER(ipLine) LIKE '%IPV4 ADDRESS%'
IF (ISNULL(@ipLine,'***') != '***')
BEGIN
SET @pos = CHARINDEX(':',@ipLine,1);
SET @ip = RTRIM(LTRIM(SUBSTRING(@ipLine , @pos + 1 ,LEN(@ipLine) - @pos)))
END
SELECT distinct(RTRIM(LTRIM(SUBSTRING(@ipLine , @pos + 1 ,LEN(@ipLine) - @pos)))) AS IPAddress FROM #TEMP
DROP TABLE #temp
SET NOCOUNT OFF
END
GO