Get IP Address of server by sql query

Script which will give IP Address of server by sql query.


CREATE TABLE #temp1
(sql_ip varchar(3000))

insert into #temp1
exec xp_cmdshell 'ipconfig'
DECLARE @ipaddress varchar(300)

-- subject to localisation
SET @ipaddress = (SELECT top 1 sql_ip from #temp1
     where sql_ip like '%Address%' order by sql_ip DESC)

declare @len int
set @Len = CHARINDEX(':', @ipaddress)

SELECT TOP 1 LTRIM(RTRIM(SUBSTRING(@ipaddress, @Len+1, LEN(@ipaddress)))) as IP_Address

drop table #temp1

Share on Facebook