package com.example;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/**
* 介绍:
* 作者:zhangxutong
* 邮箱:mcxtzhang@163.com
* 主页:http://blog.csdn.net/zxt0601
* 时间: 2016/11/25.
*/
public class TestNetworkInetAddress {
public static void main(String[] args) throws UnknownHostException {
//获取本机InetAddress的实例:
InetAddress address = InetAddress.getLocalHost();
System.out.println("本机名:" + address.getHostName());
System.out.println("IP地址:" + address.getHostAddress());
byte[] bytes = address.getAddress();
System.out.println("字节数组形式的IP地址:" + Arrays.toString(bytes));
System.out.println("直接输出InetAddress对象:" + address);
}
}