Python - Network Programming osi five agreements

8.3 osi seven layer protocol (five protocol)

Physical Layer ---> data link layer (Ethernet protocol (mac address)) ----> network layer (IP protocols) ----> transport layer (Port protocol (TCP, UDP protocol)) --- > application layer:

8.3.1 Physical Layer

A series of physical connection media: cable, optical fiber, cable

Data transmission is 01010101 bit data stream, these data continuously send and receive, to get the data useless, do not know the significance of the data represented by the data to be grouped (according to certain rules), physical layer data packets it can not do ( data link layer do)

# 交换机:将一对电脑连接在一起

交换机对照(网口与MAC地址的)表:
1:    1C-1B-0D-DA-E8-8F
2:    FF-FF-FF-FF-FF-FF
3:    FF-FF-FF-FF-FF-FF
4:    FF-FF-FF-FF-FF-FF
5:    1C-1B-0F-4A-E8-8F

网口1: 出来一条信息:

# 第一次广播的形式发出去.

网口1:源地址: 1C-1B-0D-DA-E8-8F 目标地址: 1C-1B-0F-4A-E8-8F  |   明天放假

2,3,4,5口接收到此消息,查看目标mac地址是否是自己的,

如果5口确定是自己的.记录mac地址

每个网口都广播发送消息一遍之后,对照表就构建好,下次在任意的网口在发消息,就直接以单播的形式发送.

目的: 避免局域网内每一次都广播的形式通信.以后就可以单播,提升效率.

8.3.2 Data Link Layer: Ethernet protocol

Are grouped according to certain data bit stream protocol

Ethernet protocol: that is, the data packet

How Ethernet protocol packet:

  • A set of electrical signals constitute a data packet, called a "frame"

  • Each data frame is divided into: a header and a data head data of two parts

    Header: a fixed length of 18 bytes ---> comprising: a source address, destination address, data type (each 6 bytes)

    data Data: 46 bytes <= data <= 1500 bytes

    head shortest length + data length = 64 bytes, 1518 bytes maximum, exceeds the maximum limit fragment transmission

The question: Why is the data head to be fixed?

Is a fixed standard, unified, in order to extract the source address and destination address

Question two: How Ethernet protocol source / destination address set unique?

NIC: Hardware cable in direct contact, there is a network card address --mac address, determining the physical address of the computer uniqueness

mac address: the card hexadecimal string of 12 digits: the first six digits are the manufacturer number, line number is the last six

head (source address, destination address, data type) | Data (Content)

Broadcast: The computer is the most primitive means of communication roar

Packet data (source address destination address) + Broadcast: In theory my computer can communicate with the low efficiency, each computer will need to receive broadcast messages, to see if their data is worse than broadcast storm .

So: it is broadcast range, in the same subnet LAN is broadcast by the way, a message.

LAN: Ethernet communication Radio +

服务器: 大黑盒子, 机房声音很大,对温度,湿度,等环境都有要求,双电源,双网卡,系统linux.

​ 详细解释中间环节一些特殊的功能:

​ 数据经过以太网协议封装后,先要从局域网内进行吼.每次发消息,每次都要吼,这样效率也是很低的.(数据给交换机,交换机 在分发出去.)

8.3.3 网络层 : IP协议

IP协议: IP地址 + 子网掩码 确定计算机所在网段,子网,局域网的位置(确定对方的局域网的位置)

广播,mac地址 + IP协议 == 可以找到世界上任意一台计算机.

计算机的通信:计算机的软件与服务器的软件进行通信.

IPV4地址: 四点分十进制

196.168.13.38 取值范围 0~255.0~255.0~255.0~255

子网掩码:一般都是C类: 0~255.0~255.0~255.0

# IP地址 + 子网掩码如何确定局域网的位置?
一个ip: 172.16.10.1 : 10101100.00010000.00001010.00000001

子网掩码: 255.255.255.0 : 11111111.11111111.11111111.00000000
        
AND运算得网络地址结果 : 10101100.00010000.00001010.000000001

网段,子网,局域网 : 172.16.10.0


另一个ip: 172.16.10.2 : 10101100.00010000.00001010.00000010

子网掩码: 255.255.255.0 : 11111111.11111111.11111111.00000000
    
AND运算得网络地址结果:10101100.00010000.00001010.000000001

网段,子网,局域网:  172.16.10.0
    
结果都是172.16.10.0,因此它们在同一个子网络。

# 总结一下,IP协议的作用主要有两个,一个是为每一台计算机分配IP地址,另一个是确定哪些地址在同一个子网络。

一般情况下:C类子网掩码,一个局域网能承载多少计算机?

C类子网掩码可以分配的IP数量:254个

一个局域网最多可以分配254个IP地址(同一个局域网内的IP地址不能重复) 可以连接254台计算机

通过IP地址与子网掩码可以确定对方计算机是否和自己的计算机在同一子网

如果确定在同一子网:通过广播 + 单播就可以通信

如果不确定在同一子网:

ARP协议: 就是通过对方的IP地址获取到对方的MAC地址.

如果两个用户进行第一次通信的时候,你不可能知道对方的mac地址,但是你必须要知道对方的IP地址

IP + APR协议可以获取对方的MAC地址

8.3.4 传输层:端口协议(UDP , TCP协议)

传输层:应用软件接收数据的接口

端口协议:封装端口,确定软件在计算机的位置

mac地址 + 广播形式 + IP地址 + 端口 == 可以找到世界上任意一台计算机对应的软件位置

IP地址 + 端口 == 可以找到世界上任意一台计算机对应的软件位置

端口 : 0~65535 端口号

​ 1~1023 系统占用的端口号 1024~8000之内:一般都是由软件占用

8.3.5应用层:软件自己定义的协议.

App发送数据

将数据按照自己定义的协议进行分装 , http FTP协议等

8.4 TCP协议的三次握手,四次挥手

客户端与服务端第一次建立通信联系需要三次 ' 握手 '

客户端向服务端发送建立连接请求,并给服务端发送一段序列号,服务端接收到请求之后,返回给客户端确认信号并返回建立接请求和序列号,建立连接,然后客户端再返回给服务端确认信号.

TCP协议为什么要进行 "三次握手"?

TCP协议在建立连接时,需要确认通信双方的收发信息的能力都是正常的,因此需要进行多次验证,俗称"三次握手",因此TCP协议也可以称为 " 三次握手协议 "

建立的链接不能一直连接着

四次挥手

数据发送完毕,软件也要关闭,客户端与服务端先断开连接(也有服务端与客户端断开连接)发送一个finish和序列号,服务端接收到信号,给客户端返回一个确认信息,断开客户端到服务端的连接.但是服务端到客户端的连接还存在,然后服务端还可以给客户端发送一个finish和序列号,客户端接收到服务端发送的信息,确认断开连接,再返回给服务端确认信息.

1563192958437

syn洪水攻击 : 黑客会虚拟很多的假IP,然后访问你的服务器. 服务器中有 半连接池:有缓冲的效果

Guess you like

Origin www.cnblogs.com/Agoni-7/p/11220936.html