InetAddress的实例对象包含以数字形式保存的IP地址,同时还可能包含主机名(如果使用主机名来获取InetAddress的实例,或者使用数字来构造,并且启用了反向主机名解析的功能)。InetAddress类提供了将主机名解析为IP地址(或反之)的方法。其生成
InetAddress
对象的方法(
getLocalHost()
,
getByName()
,
getAllByName()
,
getByAddress()
等)
1 import java.net.UnknownHostException; 2 3 /* 4 * To change this license header, choose License Headers in Project Properties. 5 * To change this template file, choose Tools | Templates 6 * and open the template in the editor. 7 */ 8 import java.net.*; 9 import java.util.*; 10 /** 11 * 12 * @author silianbo 13 */ 14 public class InetAddressDemo { 15 public static void main(String[] args) throws UnknownHostException{ 16 //此处添加相关的代码段 17