Get IP Address of server by sql query

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

(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

About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools