SQL获得当前连接客户端IP和机器名
2011-07-06 22:35
543 查看
create proc usp_getClient_infor as set nocount on Declare @rc int Declare @RowCount int Select @rc=0 Select @RowCount=0 begin --//create temp table ,save sp_who information create table #tspid( spid int null, ecid int null, status nchar(60) null, loginname nchar(256) null, hostname nchar(256) null, blk bit null, dbname nchar(256) null, cmd nchar(32) ) --//create temp table save all SQL client IP and hostname and login time Create table #userip( [id]int identity(1,1), txt varchar(1000), ) --//Create result table to return recordset Create table #result( [id]int identity(1,1), ClientIP varchar(1000), hostname nchar(256), login_time datetime default(getdate()) ) --//get host name by exec sp_who ,insert #tspid from sp_who, insert into #tspid(spid,ecid,status,loginname,hostname,blk,dbname,cmd) exec sp_who declare @cmdStr varchar(100), @hostName nchar(256), @userip varchar(20), @sendstr varchar(100) --//declare a cursor from table #tspid declare tspid cursor for select distinct hostname from #tspid with (nolock) where spid>50 for read only open tspid fetch next from tspid into @hostname While @@FETCH_STATUS = 0 begin select @cmdStr='ping '+rtrim(@hostName) insert into #userip(txt) exec master..xp_cmdshell @cmdStr select @rowcount=count(id) from #userIP if @RowCount=2 --//no IP feedback package begin insert into #Result(ClientIP,hostname) values('Can not get feedback package from Ping!',@hostname) end if @RowCount>2 begin select @userip=substring(txt,charindex('[',txt)+1,charindex(']',txt)-charindex('[',txt)-1) from #userIP where txt like 'Pinging%' insert into #Result(ClientIP,hostname) values(@userIP,@hostname) end select @rc=@@error if @rc=0 truncate table #userip --//clear #userIP table fetch next from tspid into @hostname end close tspid deallocate tspid select * from #result with(nolock) drop table #tspid drop table #userip drop table #result end go exec usp_getClient_infor
相关文章推荐
- 如何通过T-SQL获得当前连接的客户端的IP和机器名
- 如何通过T-SQL获得当前连接的客户端的IP和机器名...
- 如何通过T-SQL获得当前连接的客户端的IP和机器名...
- 获得本机的IP,机器名,客户端,用户名
- Xorg服务开启tcp/ip监听,允许其它机器客户端连接
- 通过新浪IP服务器获得的当前客户端IP地址对应的国家、省份或直辖市、城市信息
- Postgres Sql获取当前连接的客户端列表
- 获得当前页面客户端的IP
- C#获得客户端的IP,主机名 获取当前时间
- oracle客户端免安装配置、64位机器PL/SQL和VS自带的IIS连接问题
- SQL 获取连接客户端IP地址
- javascript获得客户端IP的又一方法
- 本机不安装Oracle客户端,使用PL/SQL Developer连接远程数据库
- 本机不安装Oracle客户端,使用PL/SQL Developer连接远程数据库
- oracle主机修改IP后客户端无法连接
- oracle 客户端可以连接11g rac vip 但是不能连接scan ip问题
- 获取当前机器的IP
- DNS 客户端无法获得域名解析的IP 故障分析
- PL/SQL Developer使用Oracle轻量客户端连接数据库
- SVN服务器IP被修改的客户端连接解决方案