Home » SQL & PL/SQL » SQL & PL/SQL » How to grep client's IP address when LOGON (oracle 10G , Window)
How to grep client's IP address when LOGON [message #518507] Thu, 04 August 2011 03:54 Go to next message
JADYCHEN
Messages: 82
Registered: July 2010
Member
Hi!! All Experts!!
How to grep client's IP address when LOGON to database??
I write a trigger , but when compile , it show Error ,
Here is code :
   CREATE OR REPLACE TRIGGER On_Logon  
     AFTER LOGON ON The_user.Schema  
   DECLARE
     v_addr VARCHAR2(11);
   BEGIN  
     IF (ora_sysevent = 'LOGON') THEN
        v_addr := ora_client_ip_address;
        raise_application_error( '-20001', 'user IP: '||v_addr);
     END IF;
   END;
   


and the Error :
ORA-30506: "system triggers cannot be based on tables or
views"
*Cause: An attempt was made to base a system trigger on a
table or a view.
*Action: Make sure the type of the trigger is compatible
with the base object.
Please help me , Thanks!!
Re: How to grep client's IP address when LOGON [message #518508 is a reply to message #518507] Thu, 04 August 2011 04:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Not what I get:
SQL> CREATE OR REPLACE TRIGGER On_Logon  
  2       AFTER LOGON ON scott.Schema  
  3     DECLARE
  4       v_addr VARCHAR2(11);
  5     BEGIN  
  6       IF (ora_sysevent = 'LOGON') THEN
  7          v_addr := ora_client_ip_address;
  8          raise_application_error( '-20001', 'user IP: '||v_addr);
  9       END IF;
 10     END;
 11  /

Trigger created.

SQL> connect scott/tiger
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: user IP:
ORA-06512: at line 6


Warning: You are no longer connected to ORACLE.

Regards
Michel
Re: How to grep client's IP address when LOGON [message #518515 is a reply to message #518508] Thu, 04 August 2011 04:57 Go to previous messageGo to next message
JADYCHEN
Messages: 82
Registered: July 2010
Member
Hi!! Dear Michel Cadot ,
I had success compile the trigger , code here :
   CREATE OR REPLACE TRIGGER On_Logon  
     AFTER LOGON  
     ON scott.Schema  
     DECLARE
        v_addr VARCHAR2(11);
     BEGIN  
        IF (ora_sysevent = 'LOGON') THEN
           v_addr := ora_client_ip_address;
            raise_application_error( '-20001', '使用者IP: '||v_addr);
         END IF;
     END;
   

but , when I re-logon scott/tiger , it seem not fire this trigger ,
and let me connect no any error ,
Please help me , Thanks!!
Re: How to grep client's IP address when LOGON [message #518516 is a reply to message #518515] Thu, 04 August 2011 05:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Copy and paste EXACTLY as I did.

Regards
Michel
Re: How to grep client's IP address when LOGON [message #518528 is a reply to message #518516] Thu, 04 August 2011 06:42 Go to previous messageGo to next message
Littlefoot
Messages: 21826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Not crucially wrong, but - the first parameter of the RAISE_APPLICATION_ERROR is a negative integer (between -20000 and -20999), not a character string.
Re: How to grep client's IP address when LOGON [message #518545 is a reply to message #518528] Thu, 04 August 2011 09:28 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
results could be less than desirable if/when application is 3-tier
Re: How to grep client's IP address when LOGON [message #518546 is a reply to message #518507] Thu, 04 August 2011 09:33 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
You will get client ip address only if tcp ip was used as connection protocol:

SQL> CREATE OR REPLACE
  2    TRIGGER On_Logon
  3      AFTER LOGON ON U1.SCHEMA
  4      BEGIN
  5          raise_application_error('-20001','user IP: ' || ora_client_ip_address);
  6  END;
  7  /

Trigger created.

SQL> connect u1/u1
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: user IP:
ORA-06512: at line 2


Warning: You are no longer connected to ORACLE.
SQL> connect u1@sol10
Enter password: **
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: user IP: XX.XXX.XXX.XXX
ORA-06512: at line 2


SQL> 


SY.
Re: How to grep client's IP address when LOGON [message #518581 is a reply to message #518546] Thu, 04 August 2011 22:18 Go to previous messageGo to next message
JADYCHEN
Messages: 82
Registered: July 2010
Member
Hi!! Dear syakobson ,
I copy and paste your code (just modify schema u1, example : user1.schema) , and compile at schema user1's
connection , then logout from user1 , and then re-logon (connect user1/xxxx@databasname) database , and then
connected no any error !! , I do'nt know what happen ?? , Please Help me , Thanks!!

[Updated on: Thu, 04 August 2011 22:19]

Report message to a moderator

Re: How to grep client's IP address when LOGON [message #518582 is a reply to message #518581] Thu, 04 August 2011 22:41 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
It is really, Really, REALLY difficult to fix a problem that can not be seen.
use COPY & PASTE so we can see what you do & how Oracle responds.

It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/
Re: How to grep client's IP address when LOGON [message #518599 is a reply to message #518582] Fri, 05 August 2011 00:48 Go to previous messageGo to next message
JADYCHEN
Messages: 82
Registered: July 2010
Member
Hi!! Dear BlackSwan ,
Sorry , now I copy and paste and show oracle response
CREATE OR REPLACE TRIGGER On_Logon AFTER LOGON ON RubyTST.SCHEMA
BEGIN
    raise_application_error('-20001','user IP: ' || ora_client_ip_address);
END;
/

and show : Trigger created.
and then connect by rubytst :
 Connect rubytst/****@orcl

and show : connected.
and then when I excute the code :
   select * from dual ;

it show the select result,that's what I happen , Please help me!! , Thanks!!
Re: How to grep client's IP address when LOGON [message #518601 is a reply to message #518507] Fri, 05 August 2011 00:49 Go to previous messageGo to next message
x-oracle
Messages: 380
Registered: April 2011
Location: gujarat
Senior Member
i did this but how can i connect with rose user now.
 1  CREATE OR REPLACE TRIGGER On_Logon
  2  AFTER LOGON ON rose.Schema
  3  DECLARE
  4  v_addr VARCHAR2(11);
  5  BEGIN
  6  IF (ora_sysevent = 'LOGON') THEN
  7  v_addr := ora_client_ip_address;
  8  raise_application_error( '-20001', 'user IP: '||v_addr);
  9  END IF;
 10* END;
 11  /

Trigger created.

SQL> conn rose/rose@moon
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 5


Warning: You are no longer connected to ORACLE.
Re: How to grep client's IP address when LOGON [message #518608 is a reply to message #518599] Fri, 05 August 2011 01:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
Sorry , now I copy and paste and show oracle response

No, you didn't do it.

Use SQL*Plus and copy and paste your session, the WHOLE session.

No help is possible without this.

Regards
Michel

[Updated on: Fri, 05 August 2011 01:20]

Report message to a moderator

Re: How to grep client's IP address when LOGON [message #518652 is a reply to message #518599] Fri, 05 August 2011 04:50 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
JADYCHEN wrote on Fri, 05 August 2011 01:48
Please help me!!


You are staring at two and a half line code for two days now and can't figure it out??? In fact, there is only one line in your code that can raise ORA-06502:

v_addr := ora_client_ip_address;

Who told you IP address is limited to 11 characters? And what's the purpose of checking ora_sysevent = 'LOGON' in AFTER LOGON trigger? Anyway, change your trigger to:

   CREATE OR REPLACE TRIGGER On_Logon  
     AFTER LOGON ON The_user.Schema  
   BEGIN  
        raise_application_error( '-20001', 'user IP: ' || ora_client_ip_address);
   END;


SY.
Re: How to grep client's IP address when LOGON [message #518653 is a reply to message #518652] Fri, 05 August 2011 05:04 Go to previous message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
One more thing. Based on:

and show : Trigger created.
and then connect by rubytst
and show : connected.

Tells me rubytst has ADMINISTER DATABASE TRIGGER privilege which ignores trigger raised exceptions.

SY.
Previous Topic: How to sned sms to mobil device??
Next Topic: display 1..2..3..5..8..13..21
Goto Forum:
  


Current Time: Sun Dec 14 06:03:21 CST 2025