zoukankan      html  css  js  c++  java
  • [java语言]——InetAddress类的getByName()方法

    InetAddress---表示互联网协议(IP)地址

       ---InetAddress.getByName("www.163.com")----在给定主机名的情况下确定主机的IP地址

                                                                            ----如果参数为null,获得的是本机的IP地址

    import java.net.*;

    public class MyHost {
             public static void main(String args[]) {
             InetAddress ip = null;

                          try {
                                  ip = InetAddress.getByName("www.baidu.com");// 修改为指定的主机名称
                                  System.out.println(ip.toString());
                                  System.out.println("主机名:" + ip.getHostName());
                                   System.out.println("主机IP地址:" + ip.getHostAddress());
                                    System.out.println("本机IP地址:"+ InetAddress.getLocalHost().getHostAddress());
                                } catch (UnknownHostException e) {
                                             e.printStackTrace();
                                                                                       }

                                                                        }
                                      }

  • 相关阅读:
    Expert C programming书摘
    修改文件时间属性的方法
    算法学习, 开始计划
    小游戏学习搜集
    C++ 练习记录2---Effective STL中的vector<bool>
    C++ 练习记录1--vector<T> 中T的初始化
    oracle的wm_concat函数实现行转列
    Oracle批量插入有日期类型数据
    如何将zTree选中节点传递给后台
    第五章:1.数组和广义表 -- 数组
  • 原文地址:https://www.cnblogs.com/JasonLGJnote/p/7822992.html
Copyright © 2011-2022 走看看