myipaddress.java

来自「java课程的资料以及实验的代码」· Java 代码 · 共 29 行

JAVA
29
字号
import java.net.*;

public class MyIPAddress

{

     public static void main(String args[])

     {

             try{
                        if(args.length == 1)
                      {
                              InetAddress ipa = InetAddress.getByName(args[0]);
                        System.out.println("Host name: " + ipa.getHostName());
                              System.out.println("Host IP Address: "  + ipa.toString());
                              System.out.println("Local Host: "+ InetAddress.getLocalHost());
                        }
                        else
                             System.out.println("Please input a host name");

              }catch(UnknownHostException e)
              {
                      System.out.println(e.toString());
              }
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?