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></o:p>

Or this

 

SELECT  *
FROM    sys.dm_exec_connections
WHERE   session_id = @@SPID

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

Rippi
2011-10-19
re: Get client IP address
Many thanks!

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!!!

ANDRIAN AV
2012-10-12
HOPEFULL I GET THE BEST CLIENT
dear client are u intresting with ACEPACK VANTURE SDN BHD? PLIZ CALL ME
IF U WANT KNOW MORE ABOUT MY COMPANY..THANX..