java Socket 获取本地主机ip

package cn.itcast.net.p1.ip;

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

public class IPDemo {

/**
  * @param args
  * @throws UnknownHostException
  */
 public static void main(String[] args) throws UnknownHostException {

//获取本地主机ip地址对象。
  InetAddress ip = InetAddress.getLocalHost();
  
  //获取其他主机的ip地址对象。
  ip = InetAddress.getByName("192.168.1.110");//InetAddress.getByName("my_think");
  
  System.out.println(ip.getHostAddress());
  System.out.println(ip.getHostName());
 }

}

上一篇:spring启动component-scan类扫描加载过程(转)


下一篇:python基础随笔