sql server 获取本机的ip地址

来源:互联网 发布:三级域名泛解析 编辑:程序博客网 时间:2024/05/16 07:16

--sql server 获取本机的ip地址

-- 其实就是使用xp_cmdshell 来获取信息,然后对信息进行筛选。




--开启xp_cmdshellexec sp_configure 'show advanced options', 1reconfigure with overrideexec sp_configure 'xp_cmdshell', 1reconfigure with overrideexec sp_configure 'show advanced options', 0reconfigure with overridego begindeclare @ipline varchar(200)declare @pos intdeclare @ip varchar(40) set nocount onset @ip = nullif object_id('tempdb..#temp') is not null drop table #tempcreate table #temp (ipline varchar(200))insert #temp exec master..xp_cmdshell 'ipconfig'select @ipline = iplinefrom #tempwhere upper (ipline) like '%IPv4 地址%'--这里需要注意一下,系统不同这里的匹配值就不同if @ipline is not nullbegin set @pos = charindex (':',@ipline,1);set @ip = rtrim(ltrim(substring (@ipline , @pos + 1 ,len (@ipline) - @pos)))end select distinct(rtrim(ltrim(substring (@ipline , @pos + 1 ,len (@ipline) - @pos)))) as ipaddress from #tempdrop table #tempset nocount offend go

原创粉丝点击