找出oracle client IP

1.从监听日志中获取:
select saddr,sid,serial#,paddr,osuser from v$session where sid = xxxx;
--andres
$ more /data/oracle/diag/tnslsnr/db-52/listener/alert/log.xml | grep USER=andres

-- <txt>15-AUG-2012 09:29:31 * (CONNECT_DATA=(SERVICE_NAME=edw1)(CID=(PROGRAM=python)(HOST=Pedrera)(USER=andres))) * (ADDRESS=(PROTOCOL=tcp)(HOST=10.0.20.121)(PORT=40944)) * establish * edw1 * 0
--抓到是10.0.20.201

2.netstat获取:
select a.sid, b.spid, b.username from v$session a, v$process b where a.paddr = b.addr and a.sid = xxxx;
--$ netstat -nap | grep spid
$ netstat -nap | grep 24614
--找出ip
$ netstat -nap | grep -i 10.0.20.201

---------
--这个SQL可以查到连接的IP,但可能只能取当前的,你可以在你确定删除动作发生的时间段来运行试试!
select user,sid,serial#,utl_inaddr.get_host_address as host,sys_context('userenv','ip_address') as local,sysdate from v$session where audsid=sys_context('userenv','sessionid');

--关于utl_inaddr.get_host_address无法获取oracle client ip

--select s.TERMINAL from v$session s where s.TERMINAL != 'unknown';
--select s.machine from v$session s;

SQL>  select s.machine from v$session s;

MACHINE
----------------------------------------------------------------
xen2227-vm02
xen-4-1-202-vm03
sha0it0nb1647
xen18-vm05

SQL> select utl_inaddr.get_host_address('xen-21202-vm02') from dual;
select utl_inaddr.get_host_address('xen-21202-vm02') from dual
       *
ERROR at line 1:
ORA-29257: host xen-21202-vm02 unknown
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1

--用strace跟踪下上面的进程:
--在调用utl_inaddr时,顺序访问了以下文件
open("/etc/resolv.conf", O_RDONLY) = 12
open("/etc/host.conf", O_RDONLY) = 12
open("/etc/hosts", O_RDONLY) = 12

首先获取域名解析服务器,在根据host.conf文件确定解析顺序,因为缺省hosts文件优先,又继续读取/etc/hosts文件。

如果hosts文件存在解析关系,则返回信息;如果不存在,则继续问询DNS服务器,获得解析地址,如果不能解析,则会出错:

也就是说,UTL_INADDR的数据获取已经不依赖于数据库信息, sys_context是依赖数据库信息的 。

本文出自 “mr.DATABASE” 博客,转载请与作者联系!

你可能感兴趣的:(oracle,listener)