Technical Article

Get SQL Server IP Address

,

You can use this to get one IP Address for the server, create a stored procedure out of it or use it with CMS to get all server IP Addresses.

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

Rate

(4)

You rated this post out of 5. Change rating

Share

Share

Rate

(4)

You rated this post out of 5. Change rating