1:得到客户端的ip地址 /************* ip **************/ declare @ip varchar(20),@hst varchar(20),@sql varchar(100) declare @str varchar(100) set @str='ping '+host_name() create table #tmp(aa varchar(200)) insert #tmp exec master..xp_cmdshell @str select top 1 @ip = replace(left(aa,charindex(':',aa)-1),'reply from ','') from #tmp where aa like 'reply from %:%' drop table #tmp select @ip
select 网卡物理地址=substring(re,charindex(':',re)+1,255) from #tb where re like '%physical address. . . . . . . . . :%'
drop table #tb
3: 将ip地址段转成每三位用点号分开 create function getip(@a varchar(15)) returns varchar(15) as begin declare @s varchar(15) set @s = '' while charindex('.',@a) > 0 begin set @s = @s + right('000' + left(@a,charindex('.',@a)),4) set @a = right(@a,len(@a)-charindex('.',@a)) end set @s = @s + right('000' + @a,3) return @s end