当前位置: 首页 > 工具软件 > HostDB > 使用案例 >

获取当前服务器Host

景俊拔
2023-12-01
1.JAVA
public void getHost(){
    try {
        InetAddress inetAddr = InetAddress.getLocalHost();
        byte[] addr = inetAddr.getAddress();
        // Convert to dot representation
        String ipAddr = "";
        for (int i = 0; i < addr.length; i++) {
            if (i > 0) {
                ipAddr += ".";
            }
            ipAddr += addr[i] & 0xFF;
        }
        System.out.println(ipAddr);
    } catch (UnknownHostException e) {
        System.out.println("Host not found: " + e.getMessage());
    }
}

 

 

2.oracle sql

select utl_inaddr.get_host_address db_server_ip from dual;

 类似资料: