create proc sp_get_hostip(@ip varchar(15) output)
AS
declare @cmd varchar(200);
create table #ipTemp(iptext varchar(255));
set @cmd = 'ping -n 1 ' + host_name();
insert #ipTemp exec master..xp_cmdshell @cmd;
select @ip = ISNULL(substring(iptext,(charindex('[',iptext)+1),(charindex(']',iptext)-(charindex('[',iptext)+1))),'') from #ipTemp where charindex('[',iptext)>0;
drop table #ipTemp;
if ( @ip <> '' )
return 1;
else
return 0;
go
--调用
declare @ip varchar(100)
exec sp_get_hostip @ip output
select @ip
本文介绍了一个SQL存储过程sp_get_hostip,用于通过执行系统命令ping来获取当前服务器的IP地址,并从返回结果中解析出IP信息。

213

被折叠的 条评论
为什么被折叠?



