0%

InetAddress类

实例化InetAddress类的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.sympa.lesson01;

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

public class InetAddressTest {

public static void main(String[] args) {
try {
//获取本机IP
InetAddress inet1 = InetAddress.getLocalHost();
System.out.println(inet1);

//获取指定域名IP
InetAddress inet2 = InetAddress.getByName("baidu.com");
System.out.println(inet2.getHostAddress());

} catch(UnknownHostException e) {
}
}
}
------ THEEND ------

欢迎关注我的其它发布渠道