通过SQL语句来获取客户端IP地址,sql触发器 获取用户名和ip

通过返回的字符串截取出IP

declare @ip varchar(15),@str varchar(100)
set @str='ping '+Host_Name()--通过ping 主机名来获取返回的字符串,ping 后要加空格
create table #temp(ipStr varchar(300))
insert into #temp exec master..xp_cmdshell @str
select top 1 @ip=replace(left(ipStr,charindex(':',ipStr)-1),'Reply from ','')--替换的时候Reply from
from #temp where ipStr like 'Reply from %:%'
drop table #temp
select @ip

原文地址:https://www.cnblogs.com/Luouy/p/1893403.html