识别主机名和IP地址
文章来源:https://oracle-base.com/articles/misc/identifying-host-names-and-addresses
Identifying Host Names and IP Addresses
识别主机名和IP地址
This article presents a mixed bag of Oracle functionality relating to the identification of host names and IP addresses for Oracle clients and servers.
该篇文章展示了一系列关于识别Oracle客户端和服务器主机名和IP地址的方法。
1、UTL_INADDR
2、SYS_CONTEXT
3、V$INSTANCE
4、V$SESSION
1、UTL_INADDR
The UTL_INADDR package was introduced in Oracle 8.1.6 to provide a means of retrieving host names and IP addresses of remote hosts from PL/SQL.
The GET_HOST_ADDRESS function returns the IP address of the specified host name.
SQL> SELECT UTL_INADDR.get_host_address('bart') FROM dual;
UTL_INADDR.GET_HOST_ADDRESS('BART')
--------------------------------------------------------------
192.168.2.4
The IP address of the database server is returned if the specified host name is NULL or is omitted.
如果主机名未指定默认返回数据库服务器所在IP地址。
SQL> SELECT UTL_INADDR.get_host_address from dual;
GET_HOST_ADDRESS
--------------------------------------------------------------
192.168.2.5
An error is returned if the specified host name is not recognized.
如果指定的主机名不存在则返回错误。
SQL> SELECT UTL_INADDR.get_host_address('banana') from dual;
SELECT UTL_INADDR.get_host_address('banana') from dual
*
ERROR at line 1:
ORA-29257: host banana unknown
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1
The GET_HOST_NAME function returns the host name of the specified IP address.
SQL> SELECT UTL_INADDR.get_host_name('192.168.2.4') FROM dual;
UTL_INADDR.GET_HOST_NAME('192.168.2.4')
--------------------------------------------------------------
bart
The host name of the database server is returned if the specified IP address is NULL or omitted.
SQL> SELECT UTL_INADDR.get_host_name FROM dual;
GET_HOST_NAME
--------------------------------------------------------------
C4210gR2
1 row selected.
An error is returned if the specified IP address is not recognized.
SQL> SELECT UTL_INADDR.get_host_name('1.1.1.1') FROM dual;
SELECT UTL_INADDR.get_host_name('1.1.1.1') FROM dual
*
ERROR at line 1:
ORA-29257: host 1.1.1.1 unknown
ORA-06512: at "SYS.UTL_INADDR", line 4
ORA-06512: at "SYS.UTL_INADDR", line 35
ORA-06512: at line 1
2、SYS_CONTEXT
The SYS_CONTEXT function is able to return the following host and IP address information for the current session:
SYS_CONTEXT函数可返回当前会话的以下信息:
1) TERMINAL - An operating system identifier for the current session. This is often the client machine name.
2) HOST - The host name of the client machine.
3) IP_ADDRESS - The IP address of the client machine.
4) SERVER_HOST - The host name of the server running the database instance.
The following examples show the typical output for each variant.
SQL> SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual;
SYS_CONTEXT('USERENV','TERMINAL')
--------------------------------------------------------------
marge
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','HOST') FROM dual;
SYS_CONTEXT('USERENV','HOST')
--------------------------------------------------------------------
marge
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;
SYS_CONTEXT('USERENV','IP_ADDRESS')
--------------------------------------------------------------
192.168.2.3
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','SERVER_HOST') FROM dual;
SYS_CONTEXT('USERENV','SERVER_HOST')
--------------------------------------------------------------
C4210gr2
1 row selected.
3、V$INSTANCE
The HOST_NAME column of the V$INSTANCE view contains the host name of the server running the instance.
SQL> SELECT host_name FROM v$instance;
HOST_NAME
------------------------------------------------
C4210gR2
1 row selected.
4、V
SESSIONTheV
<script type="math/tex" id="MathJax-Element-2">SESSION
The V</script>SESSION view contains the following host information for all database sessions:
1) TERMINAL - The operating system terminal name for the client. This is often set to the client machine name.
2) MACHINE - The operating system name for the client machine. This may include the domain name if present.
The following examples show the typical output for each column.
SQL> SELECT terminal, machine FROM v$session WHERE username = 'TIM_HALL';
TERMINAL MACHINE
------------------------------ -------------------------------
MARGE ORACLE-BASE\MARGE
1 row selected.
识别主机名和IP地址的更多相关文章
- Solaris 10主机名和IP地址步骤
1.修改主机名: hostname newname vi /etc/hosts vi /etc/hostname.e1000g0 vi /etc/nodename init 6 #重启 --confi ...
- 二十二、utl_inaddr(用于取得局域网或Internet环境中的主机名和IP地址)
1.概述 作用:用于取得局域网或Internet环境中的主机名和IP地址. 2.包的组成 1).get_host_name作用:用于取得指定IP地址所对应的主机名语法:utl_inaddr.get_h ...
- Linux学习笔记(10)linux网络管理与配置之一——主机名与IP地址,DNS解析与本地hosts解析(1-4)
Linux学习笔记(10)linux网络管理与配置之一——主机名与IP地址,DNS解析与本地hosts解析 大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配 ...
- java 获取局域网中的全部主机名和IP地址
DOS命令 命令 意义 net view 获取局域网中的全部主机名 ipconfig -all 获取本地IP,主机名,MAC地址 arp -a 获取本局域网中的全部IP地址和物理地址 ping -a ...
- gethostbyname() -- 用域名或主机名获取IP地址
#include <netdb.h> #include <sys/socket.h> struct hostent *gethostbyname(const char * ...
- Linux CentOS7.0 (02)修改主机名和ip地址
一.主机名修改 1.查看命令 在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient),和灵活的(pretty). "静态"主机名也称为内核主机名 ...
- Asp.net MVC获取访问系统的客户端计算机的主机名和IP地址
string HostName = string.Empty; string ip = string.Empty; string ipv4 = String.Empty; if (!string.Is ...
- (转)gethostbyname() -- 用域名或主机名获取IP地址
struct hostent *gethostbyname(const char *name); 这个函数的传入值是域名或者主机名,例如"www.google.cn"等等.传出值, ...
- 修改Linux的基本配置(修改主机名修改ip地址安装JDK/Tomcat/MySQL等等)
(一)基本操作修改 修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=server1.itcast.cn 修改ip地址 vi /etc/s ...
- gethostname(获取主机名)、gethostbyname(由主机名获取IP地址)
int gethostname(char *name, size_t len);获取本地主机名存入name[len],成功返回0,失败返回-1: struct hostent * gethostbyn ...
随机推荐
- [转帖]【sql server安全】sql server连接加密,sql server SSL加密连接
https://www.cnblogs.com/gered/p/13595098.html#_label1_0 MSSQL - 最佳实践 - 使用SSL加密连接 回到顶部 author: 风移 回到顶 ...
- [转帖]浅析SQL数据类型的隐式转换与显式转换以及隐式转换可能导致的问题
https://www.cnblogs.com/goloving/p/15222604.html 一.隐式类型转换问题 1.隐式类型转换: 比如:SELECT 1 + '1'; 2.隐式类型转换的问题 ...
- [转帖]jmeter必备正则表达式
元字符 . 注意是一个点号,表示匹配任意单个字符 \d 表示匹配任意单个数字 [0-9] 等价于0-9 [a-zA-Z] 等价于所有的大小写字母 限定符 + 加号,表示匹配至少大于1次(1次或多次 ...
- [转帖]看看 Jmeter 是如何玩转 redis 数据库的
柠檬小欧 2021-08-31 20:06420 Jmeter 作为当前非常受欢迎的接口测试和性能测试的工具,在企业中得到非常广泛的使用,而 Redis 作为缓存数据库,也在企业中得到普遍使用,那如何 ...
- Linux时间戳转换成易读格式的方法
背景 最近一直在学习Redis相关的知识. 其中遇到了一个redis monitor的命令 但是这里有一个问题是: 原生命令查询出来的时间是Unix时间戳格式的. 不太好发现查看与进行对照. 所以今天 ...
- Oracle 高版本导出到低版本的测试验证
今天验证Oracle 由高版本 备份恢复到低版本 与方神沟通(双 还是他) 说可以使用 version的参数..然后搞一下.. expdp system/Test6530@ora12cr2 schem ...
- 六个节点三主三从Redis集群最简单搭建方法
背景 一个服务器上面的三主三从的界面太low,容易出问题. 为了验证高可用, 我这边使用六台机器进行了三主三从的搭建. 模仿开源版的一键搭建集群的脚本进行使用,感觉非常简单,这里简单进行一下总结. 环 ...
- 我在京东做研发 | 揭秘支撑京东万人规模技术人员协作的行云DevOps平台
随着业务变化的速度越来越快各类IT系统的建设也越来越复杂大规模研发团队的管理问题日益突出如何提升研发效能成为时下各类技术团队面临的重要挑战 京东云DevOps专家将带您深入研发一线揭秘支撑京东集团万人 ...
- Spring Boot接口设计
项目文件结构 编写示例代码 添加lombok的依赖 新建DemoController,用于提供RESTful接口.增加相关注解:@RestController,@RequestMapping(&quo ...
- Go Plugin介绍
以下内容来自官方文档. go version: 1.17.5 综述 plugin包实现了Go插件的加载和符号解析. Go插件是一个包括了可导出函数和变量的main包(可以没有main()函数),构建时 ...