Peter Larsson Blog

Patron Saint of Lost Yaks

Get client IP address

Up until now, I have used convuluted approaches to get the current user client IP-address.
This weekend I browsed Books Online for SQL Server 2008 R2 (November CTP) and found this new cool function!

SELECT  CONNECTIONPROPERTY('net_transport') AS net_transport,
        CONNECTIONPROPERTY('protocol_type') AS protocol_type,
        CONNECTIONPROPERTY('auth_scheme') AS auth_scheme,
        CONNECTIONPROPERTY('local_net_address') AS local_net_address,
        CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port,
        CONNECTIONPROPERTY('client_net_address') AS client_net_address/o:p

Or this

  /o:p

SELECT  *
FROM    sys.dm_exec_connections
WHERE   session_id = @@SPID
/o:p

Legacy Comments


K.E.M Asif
2011-03-15
re: Get client IP address
Good..thanks

arben
2011-06-25
re: Get client IP address
pls can you send my client IP adress/ pls........

Faris
2011-07-24
re: Get client IP address
thanks a lot

thankful
2012-02-01
re: Get client IP address
SELECT *
FROM sys.dm_exec_connections
WHERE session_id = @@SPID

works with sql server 2005 .. great job man... thx a lot!!!