网络学习
ip
ip地址:IntAddress
ip地址的分类
ipv4/ipv6
- ipv4 127.0.0.1,4个字节组成
- ipv6 , 128位,8个无符号整数
IP查询:终端+ipconfig
//查询本机地址
InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");
System.out.println(inetAddress1);
InetAddress inetAddress3 = InetAddress.getByName("localhost");
System.out.println(inetAddress3);
InetAddress inetAddress4 = InetAddress.getLocalHost();
System.out.println(inetAddress4);
//查询网站地址
InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");
System.out.println(inetAddress2);
端口
端口分类
-
公有端口:0~1023
HTTP:80
HTTPS:443
FTP:21
Telent:23
-
程序注册端口:1024~49151(分配用户或者程序)
Tomcat:8080
MySQL:3306
Oracle:1521
-
动态、私有:49152~65535
netstat -ano//查看所有端口
netstat -ano|findstr "5353"//查看指定端口
tasklist|findstr "17072"//查看指定进程
Ctrl+shift+Esc //打开任务管理器
import java.net.InetSocketAddress;
public class Socket {
public static void main(String[] args) {
//InetSocketAddress可以使用new
InetSocketAddress socketAddress=new InetSocketAddress("127.0.0.1",8080);
InetSocketAddress socketAddress1=new InetSocketAddress("localhost",8080);
System.out.println(socketAddress);
System.out.println(socketAddress1);
}
}