审计sqlserver ip和主机名
declare @ip varchar(200)
select @ip='' declare @num int select @num=1 while(@num=1) begin SELECT @ip=b.[client_net_address] FROM MASTER.sys.dm_exec_sessions a? INNER JOIN MASTER.sys.dm_exec_connections b? ON a.session_id=b.session_id? and a.[host_name]='0.0.0.0' --and a.[host_name]='book3' if @@rowcount>0 begin print @ip select @num=0 end end select b.[session_id],b.[login_time],b.[host_name],b.[original_login_name],a.[client_net_address],a.TEXT? ---------------------------------------------------------------------------------------------------------------------------- 创建IP和主机名对应关系表 USE [xxxxxxx] 一秒钟执行一次新连接插入audit_host表 declare @num int select @num=1 while(@num=1) begin insert into audit_host select * from (SELECT? distinct a.[host_name],b.[client_net_address]? FROM MASTER.sys.dm_exec_sessions a WITH(NOLOCK) INNER JOIN MASTER.sys.dm_exec_connections b WITH(NOLOCK) ON a.session_id=b.session_id) c where not exists (select 1 from audit_host d where c.[host_name]=d.[host_name] and c.[client_net_address]=d.[client_net_address]) WAITFOR DELAY '00:00:01' end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |