|
試試看如何﹖
select spid,dbid,hostname,program_name,net_address from sysprocesses
create table #temp1(ip varchar(254))
create table #temp2(host varchar(64),ip varchar(254))
declare @host varchar(64),@ip varchar(64),@i int
declare cur_ip cursor local for
select distinct hostname from sysprocesses where hostname is not null and spid > 48
open cur_ip
fetch cur_ip into @host
while @@fetch_status = 0
begin
insert into #temp1 exec master.. xp_cmdshell 'ping Ad002'
select top 1 ip into #temp3 from #temp1 where ip like 'Reply from%'
select @ip =ip from #temp3
select @ip = substring(@ip,12,len(@ip))
select @i = charindex(':',@ip)
select @ip=substring(@ip,1,@i - 1)
insert into #temp2 values(@host,@ip)
fetch cur_ip into @host
delete from #temp1
delete from #temp3
end
close cur_ip
select * from #temp2
drop table #temp1
drop table #temp2
drop table #temp3 |
|