How to use the client_info field in v$session view to track the client IP address
This article mainly introduces how to use the client_info field in the v$session view to track the client IP address, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
You cannot get the client IP directly from v$session by default, and you need to execute the dbms_application_info.set_client_info stored procedure to record the IP address of the login data terminal in the client_info field.
You can use the following methods to create triggers to accomplish the function of automatically recording IP addresses:
Create or replace trigger login_on_record_ip
After logon on database
Begin
Dbms_application_info.set_client_info (sys_context ('userenv',' ip_address'))
End
/
Experiment:
1. Use the terminal to remotely log in to the database as the SCOTT user and query the client_info field in the v$session view.
SQL > select sid,serial#,username,terminal,client_info from v$session where username='SCOTT'
SID SERIAL# USERNAME TERMINAL CLIENT_INFO
54 62937 SCOTT SAM_DBA
two。 Execute create trigger
SQL > create or replace trigger login_on_record_ip
2 after logon on database
3 begin
4 dbms_application_info.set_client_info (sys_context ('userenv',' ip_address'))
5 end
6 /
Trigger created.
3. Disconnect the SCOTT user, use the terminal again to remotely log in to the database as the SCOTT user, and query the client_info field in the v$session view.
SQL > select sid,serial#,username,terminal,client_info from v$session where username='SCOTT'
SID SERIAL# USERNAME TERMINAL CLIENT_INFO
54 62945 SCOTT SAM_DBA 192.168.10.2
At this point, you can look at the CLIENT_INFO column in the V$SESSION view to see the client IP address of the new login.
Thank you for reading this article carefully. I hope the article "how to use the client_info field in the v$session view to track the client IP address" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!