0

If we have our website deployed on server "A", and a user requests a page in this website from his machine "B". Can we get the IP Address of "B" from database server "C" which is connected to "A". For example at the time of logging in when I authenticate my user whose credentials are stored in "C", do we have any T-SQL statement to trace the IP address of the user.

I can read the IP address using ASP.Net but I want to know if it can be done from the SQL Server itself.

I googled and which suggests using SYS.DM_EXEC_CONNECTIONS. But that is applicable when we need to get the IP Address of client connected to database.

May be it is impossible to implement what I am asking. The problem is that I am new to IT world. I will appreciate any help or suggestion.

Thanks in advance

Javid Ahmad
  • 51
  • 1
  • 5

1 Answers1

0

SQL Server doesn't know or differentiate between the different clients that connect to it. In this case, the only client SQL Server knows about is the application/scripts on your webserver (A). The actual end user B is effectively masked from SQL Server by the webserver. As far as SQL Server is concerned, the only known client is the webserver since that's the only source of connections to SQL Server.

You can get the IP from your asp.net application (as you've indicated) and pass that to SQL Server. Do remember that IPs and headers can be spoofed easily. Also, most users connect via some corporate network or ISP so the IP you get is almost certainly from a shared block used by the organization for external connections. The same user on the same computer can connect again minutes later with a completely different IP without doing anything at all.

SQLmojoe
  • 1,924
  • 1
  • 11
  • 15