端口表示计算机上一个程序的进程
不同的进程有不同的端口号!用来区分软件!
被规定为0~65535
TCP,UDP\65535乘2 TCP\80 UDP\80 单个协议下,端口号不能冲突
共有端口:0~1023
程序注册端口:1024~49151
动态,私有端口:49152~65535
package programming;
import java.net.InetAddress;
import java.net.UnknownHostException;
//测试IP地址类
// 定义一个名为TestAddress的类
public class TestAddress {
// 主函数
public static void main(String[] args) {
try {
// 通过IP地址获取InetAddress对象并打印
//查询本地主机的IP地址
InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");
System.out.println(inetAddress1);
// 通过主机名获取InetAddress对象并打印
InetAddress inetAddress2 = InetAddress.getByName("localhost");
System.out.println(inetAddress2);
// 获取本地主机的InetAddress对象并打印
InetAddress inetAddress3 = InetAddress.getLocalHost();
System.out.println(inetAddress3);
//查询域名对应的IP地址
// 通过域名获取InetAddress对象并打印
InetAddress inetAddress4 = InetAddress.getByName("www.google.com");
System.out.println(inetAddress4);
// 打印InetAddress对象的规范主机名
//常用方法
System.out.println(inetAddress4.getCanonicalHostName());
// 打印InetAddress对象的IP地址字符串
System.out.println(inetAddress4.getHostAddress());
//打印InetAddress域名,或者自己电脑的主机名
System.out.println(inetAddress4.getHostName());
}
// 捕获未知主机异常
catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
标签:端口,System,IP地址,println,InetAddress,out
From: https://www.cnblogs.com/gang-pao/p/18178122