create table #ip(id int identity(1,1),re varchar(200))
declare @s varchar(1000)
set @s='ping '+host_name()+' -a -n 1 -l 1'
insert #ip(re) exec master..xp_cmdshell @s
select 登录的用户=suser_sname(),计算机名=host_name(),IP地址=stuff(left(re,charindex(']',re)-1),1,charindex('[',re),'')
from #ip
where id=2
drop table #ip