• 网络编程中获取域名和id的方法


    package com.lanqiao.java.test;

    import java.net.InetAddress;
    import java.net.UnknownHostException;

    public class testInetAddress {

    public static void main(String[] args) throws Exception {
    InetAddress inet=InetAddress.getByName("www.atguigu.com");//通过域名获取

    System.out.println(inet);//获取域名和ip
    System.out.println(inet.getHostName());//获取ip地址对应的域名
    System.out.println(inet.getHostAddress());//获取ip地址
    System.out.println();

    InetAddress inet1=InetAddress.getLocalHost();//获取本机的ip,域名
    System.out.println(inet1);
    System.out.println(inet1.getHostName());//获取本机域名
    System.out.println(inet1.getHostAddress());//获取本机的ip地址
    }

    }

  • 相关阅读:
    [HAOI2008]糖果传递
    [HAOI2008]木棍分割
    [HAOI2008]硬币购物
    [ZJOI2008]泡泡堂
    [JSOI2007]建筑抢修
    [JSOI2007]麻将
    [Note]prufer
    [BZOJ3275]Number
    [POI2014]RAJ-Rally
    [JSOI2010]快递服务
  • 原文地址:https://www.cnblogs.com/lxnlxn/p/5762719.html
Copyright © 2020-2023  润新知