Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to get hostname and IP address in Oracle

Shulou Source: shulou.com Published: 2022-06-01 16:42:51 09月20日 Update

This article introduces how to get the host name and IP address in Oracle. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Using the sys_context function, we can obtain 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

Through sys_context, we can only get information about the current session. What if we want to get other session?

At this point, we use the utl_inaddr package to get

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 the ip of sina and other web site

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: first get the domain name resolution server (resolv.conf), according to the host.conf file to determine the resolution order, because the default is hosts file priority parsing, this time will continue to read / etc/hosts file.

If there is a parsing relationship in the hosts file, the information is returned; if it does not exist, continue to consult the DNS server to get the parsing address, and if it cannot be resolved, 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: unknown host www.a.com

ORA-06512: in "SYS.UTL_INADDR", line 35

ORA-06512: in "SYS.UTL_INADDR", line 40

ORA-06512: in line 1

So much for sharing about how to get the host name and IP address in Oracle. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: File host address information content time more server help service good interest function principle domain name partner article knowledge article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker Xiaomi macOS OPPO Reno