This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12522|Reply: 0

[Communication] Oracle

[Copy link]
Posted on 1/24/2015 1:22:57 PM | | |

Using sys_context function we can get the hostname and IP address of the current session
SQL> select sys_context('userenv','host') from dual;
SYS_CONTEXT('USERENV','HOST')
--------------------------------------------------------------
WORKGROUP\IBM-L3YMBNP
SQL> select sys_context('userenv','ip_address') from dual;
SYS_CONTEXT('USERENV','IP_ADDRESS')
-----------------------------------------------------------
127.0.0.1
By sys_context we can only get the information of the current session, what if we want to get other sessions?
At this time, we use utl_inaddr pack to get it
SQL> select utl_inaddr.get_host_address('IBM-L3YMBNP') from dual;
UTL_INADDR. GET_HOST_ADDRESS('IBM-L3YMBNP')
-------------------------------------------------------------------
9.181.142.152
And we can also get IPs for SINA and other web sites
SQL> select utl_inaddr.get_host_address('www.sina.com.cn') from dual;
UTL_INADDR. GET_HOST_ADDRESS('WWW. SINA.COM. CN')
---------------------------------------------------------------------
218.30.108.55
The principle is to first obtain the domain name resolution server (resolv.conf), and then determine the resolution order based on the host.conf file, because the default is to prioritize the resolution of the hosts file, and then continue to read the /etc/hosts file.
If the hosts file has a parsing relationship, it returns information; If it doesn't exist, then continue to ask the DNS server to get the resolution address, and if it can't, an error will occur
SQL> select utl_inaddr.get_host_address('www.a.com') from dual;
select utl_inaddr.get_host_address('www.a.com') from dual
       *
ERROR is on line 1:
ORA-29257: 未知的主机 www.a.com
ORA-06512: 在"SYS.UTL_INADDR", line 35
ORA-06512: 在"SYS.UTL_INADDR", line 40
ORA-06512: 在line 1
That's basically it.




Previous:ORALCE obtains the hostname and IP address
Next:Oracle Password HASH algorithm evaluation
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com