获取客户端IP地址

-->Title:Generating test data

-->Author:wufeng4552

-->Date :2009-09-23 10:34:02

-->功能:获客户IP地址

if object_id('GetClientIP')is not null drop proc GetClientIP

go

create procedure GetClientIP

@host_name varchar(30),

@ip varchar(30)output

as

declare @str varchar(100)

declare @t table(IP varchar(200))

set @str='ping '+@host_name+' -n 1'

insert @t exec master..xp_cmdshell @str

select top 1 @ip = replace(left(IP,charindex(':',IP)-1),'Reply from ','')

from @t where IP like 'reply from %:%'

go

declare @ip varchar(20)

exec GetClientIP 'www.sina.com.cn ',@ip output

select @ip

/*

--------------------

218.30.108.185

(1 個資料列受到影響)

*/

你可能感兴趣的:(XP,Go)