Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get client's IP Address or Server Name

0 views
Skip to first unread message

AA

unread,
Apr 7, 2003, 10:37:59 AM4/7/03
to
I would like to add a trigger on the table to collect the
server name of the Client machine.

How can I do it?

Steve Thompson

unread,
Apr 7, 2003, 11:03:24 AM4/7/03
to
"AA" <a...@yahoo.com> wrote in message
news:03e301c2fd13$4977f740$a401...@phx.gbl...

> I would like to add a trigger on the table to collect the
> server name of the Client machine.
>
> How can I do it?
>
Host name you can get from the Host_name variable:

select Host_name()

IP Address is trickier... It's possible you might be able to retrieve this
from the sysprocesses table. Or, perhaps write some VBScript code to
retrieve this information.

Steve


John Bell

unread,
Apr 7, 2003, 1:31:21 PM4/7/03
to
Hi

If you are just wanting to get the name, then you can use the host_name()
function in your original statement and there is no need for a trigger.

John

"AA" <a...@yahoo.com> wrote in message
news:03e301c2fd13$4977f740$a401...@phx.gbl...

Jasper Smith

unread,
Apr 7, 2003, 4:16:20 PM4/7/03
to
Host + IP if available

create proc sp_get_hostip (@spid int = NULL)
as
set nocount on

declare @host varchar(100)
declare @ip varchar(15)
declare @cmd varchar(200)
declare @temp varchar(255)
create table #ip(iptext varchar(255))

If @spid is null select @host = host_name()
else
select @host = max(hostname)
from master..sysprocesses
where spid = @spid

if @host is not null
begin
set @cmd = 'ping -n 1 ' + @host
insert #ip exec master..xp_cmdshell @cmd
select @ip = ISNULL(substring(iptext,(charindex('[',iptext)+1),
(charindex(']',iptext)-(charindex('[',iptext)+1))),'')
from #ip
where charindex('[',iptext)>0
end

drop table #ip
select NULLIF(rtrim(@host),'') as 'Hostname',
rtrim(@ip) as 'IP_Address'

return

--
HTH

Jasper Smith (SQL Server MVP)

I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org

"AA" <a...@yahoo.com> wrote in message
news:03e301c2fd13$4977f740$a401...@phx.gbl...

0 new messages