Cari Blog Ini

22 Oktober 2012

How To Get SQL Server IP Address


1. Query

-----code:start-----------------------------------------------------------------------------

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%'

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


-----code:end-----------------------------------------------------------------------------


Source:
http://www.sqlservercentral.com/scripts/IP+Addresses/75193/
Article: Get SQL Server IP Address
By Shirley Noa