自学1

网络通信

InetAddress类

import java.net.*;

public class Address {

    public static void main(String[] args) {
        InetAddress ip; // 创建InetAddress类对象
        try{
            ip = InetAddress.getLocalHost(); // 实例化对象
            String localname = ip.getHostName();
            String localip = ip.getHostAddress();
            System.out.println(localname);
            System.out.println(localip);
        }catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }

}

你可能感兴趣的:(学习)