package com.immooc;
/*
* InetAddress类
*/
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
public class Test01 {
/**
* @param args
*/
public static void main(String[] args) throws UnknownHostException {
// TODO Auto-generated method stub
//获取本机的InetAddress实例
InetAddress address =InetAddress.getLocalHost();
System.out.println(“计算机名:”+address.getHostName());
System.out.println(“IP地址:”+address.getHostAddress());
byte[] bytes=address.getAddress();//获取字节数组形式的IP地址
System.out.println(“字节数组形式的IP:”+Arrays.toString(bytes));
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/11881.html