Java获取电脑的IP及电脑名

//程序入口
public static void main(String[] args) throws UnknownHostException {
  // 获取IP地址        
  String ip = InetAddress.getLocalHost().getHostAddress();  
  // 获取计算机名          
  String name = InetAddress.getLocalHost().getHostName();          
   //打印              
  System.out.println("IP地址:"+ip); 
  System.err.println("计算机名:"+name);  
 }

猜你喜欢

转载自blog.csdn.net/qq_36093146/article/details/80278411