The Python Network Programming (a) network programming acquaintance

Network Programming acquaintance
C / SB / S architecture
C / SB / S architecture

C: browse browser S:: server terminal B client terminal

C / S architecture: the basis between the client and server communications

QQ, games, shrimp Phi, deft, vibrato.

Advantages: Personalization, fast response,

Cons: development costs, maintenance costs, space, user fixed.

B / S architecture: based communication between the browser and the server

Google browser, 360 browser, Firefox, and so on.

Advantages: Low development and maintenance cost, space is relatively low, the user is not fixed.

Disadvantages: single function, there is no personalization, response speed is relatively slow.

Network communication theory
80 years, fixed telephone, (not the promotion of Putonghua)

A bunch of physical media connection between two telephone connections.
Dial, the locked position of the other phone.
Since there was no unity in Mandarin, so if you and Henan, Shanxi, Guangxi, Fujian and other friends and friendly communication, you have to learn the local dialect.

Promotion of Putonghua, unified communication.

A pile of physical media connection between two telephone connections
. Dial position, lock the other side of the phone
. Unification of communication
worldwide exchange:

A pile of physical media connection between two telephone connections
. Dial position, lock the other side of the phone
. Unification of communication (English)
topic back to Internet communication:

I now want the United States to contact a girl. How do you use a computer link ???

Both computers must be connected to a bunch of physical media connection.
Locate the position of other computer software.
Follow package of Internet communication protocols.
Osi seven layer protocol
osi seven layer protocol
application layer presentation layer session layer transport layer network layer data link layer physical layer

Physical layer:

It refers to the physical layer of the network cable, fiber optic, twisted pair physical connection medium etc.

Bitstream: bit 0101 is like sending a steady stream of water 010 101 001.

data link layer:

The data link layer a bitstream packet.

Switch: the switch is a kind of wide-area information to complete the function of the shunt switching device in a communication system

Router: A router is connected to two or more network hardware devices, play the role of a gateway between networks, a read address of each packet and determine specific intelligent network device how to transfer.

External network (public) IP, means that the specified network segment connected to the external Internet

Network (LAN) IP are false, DHCP protocol: IP address of the router automatically distributed, gateway, and so on.

Ethernet protocols: the bit stream into logical groupings.

head | data # header | data

head: 18 bytes: source mac address | target address mac | Data Type

data: a minimum of 46 bytes, a maximum of 1500 bytes.

Mac mac address of the source address of the target data type | the Data
mac address: the computer network card address marked on the .12 hexadecimal digits: the first six digits are the manufacturer ID, the line number is six.

Switch mac learning function:

The first transmission format of a broadcast message, when the port learning mac address correspondence table recorded in the transmission message: send a unicast form.

Two computer communication:

Unicast: Unicast is a point to point connection between the client and the server.

Broadcast: In the broadcast network, there are multiple networked computers share a common channel, when a computer using the shared packet channel transmission packet, all other computers are "listening" to the packet.

Network layer:

IP protocol: determining the location of a local area network (subnet) of (four decimal points)

Range of 0 to 255.0 ~ 255.0 ~ 255.0 ~ 255

Subnet Mask: C Class Subnet Mask: 255.255.255.0

+ ip address subnet mask bitwise AND out whether in the unified local area network (subnet segment)
Class C subnet mask network can carry up to a plurality of IP addresses?

254 are all zero tail to tail all 1's gateway address broadcast address

ARP protocol: Get to the other side of the mac address ip address of the other party.

to sum up:

Prerequisite: know the target mac:

A computer sends a message to computer B

Source mac mac source IP target target IP data

Unicast form is sent to the switch, the switch will detect your table there is no target mac, if there is, if there is no unicast transmission, referred to on the floor: a router, the router receives a message, the message is analyzed, to determining whether the target computer and the computer is the same network segment, if the same segment, is directly sent to the corresponding switch, the switch to the target broadcast single mac.

If it is not in the same network segment:?

Premise: do not know the target mac:

A computer sends a message to computer B

Source goal mac mac does not know the source IP Destination IP data

Sends a unicast form to the switch, handed over on one router: the router receives a message, the message is analyzed to determine the target computer and the computer on the same network segment, if in the same segment by IP and ARP protocol get to the other side of the mac address, and then in communications.

Transport Layer:

Port Protocol: UDP protocol, TCP protocol

After a total of 65535 port can be 0 to 1023 system, select their own port 8080: port.

UDP TCP protocol
TCP (Transmission Control Protocol) reliable, connection-oriented protocol (eg: call), streaming protocols, full-duplex communication of low transmission efficiency (transmission & reception buffer cache), the byte stream oriented. Applications using TCP: Web browser; file transfer program.

UDP (User Datagram Protocol) unreliable, connectionless service, the transmission efficiency (transmission pre small delay), one to one, one to many, many-to-many, for messages (data packets), best effort service, no congestion control. Applications using UDP: Domain Name System (DNS); video streaming; IP voice (VoIP).

TCP three-way handshake protocol and four waving
syn flood attack: create a large number of fake invalid IP requests resulting in server could not access the normal IP server.

Three-way handshake Description:

Set Concept: The TCP header field, there are three important identifying the ACK, the SYN, the FIN
the ACK: verification field indicates
the SYN: the number of bits set to 1, indicates TCP connection is established
the FIN: the number of bits set to 1, indicates the TCP connection is disconnected

1, the client sends a TCP connection establishment request packet, wherein the packet includes a sequence number seq, is randomly generated by the sender, and a field to the SYN packet is 1, represents a TCP connection is required. (SYN = 1, seq = x, x is a randomly generated value)

2, the server replies to the client transmits TCP connection request packet containing seq serial number, by the return end of randomly generated, and the SYN is set to 1, and generates the ACK field, ACK field value at the client sent from the base sequence number seq of plus 1 to reply to the client upon receipt of information, the establishment of its own TCP request has been verified. (SYN = 1, ACK = x + 1, seq = y, y is a randomly generated value) plus an ACK herein can be understood as a connection acknowledgment whom.

3, the client receives the TCP server sent after the establishment of the verification request, make its own serial number plus 1 indicates, and replies ACK request verification again, add 1 reply on the server sent me seq. (SYN = 1, ACK = y + 1, seq = x + 1)

Four waved process Description:

1, the client sends a TCP connection request packet is disconnected, wherein the packet includes a sequence number seq, is randomly generated by the sender, and the field is set to FIN packets is also 1, indicating that need to disconnect the TCP connection . (FIN = 1, seq = x, x randomly generated by the client)

2, the server will respond to client sends a TCP disconnection request packet comprising a sequence number seq, is randomly generated by the return side, and will have ACK field, ACK field values ​​are sent, the client's sequence number seq plus 1 on the basis of replies to the client upon receipt of information, know their TCP disconnect request has been verified. (FIN = 1, ACK = x + 1, seq = y, y randomly generated by the server)

3, the server replies after completion of the client's TCP disconnect request, TCP connection will not be disconnected immediately, the server will first ensure that once data transfer is complete before disconnecting confirm that all data is transferred to the A's have been transferred, it will return the FIN packet field set to 1, and generates a random sequence number seq. (FIN = 1, ACK = x + 1, seq = z, z randomly generated by the server)

4, the client receives TCP disconnect the server request, the server will respond to the disconnect request, the ACK field and a field comprising seq randomly generated, plus seq. 1 will be the basis of the ACK field in a TCP disconnection request to the server, thereby complete server request validation reply. (FIN = 1, ACK = z + 1, seq = h, h is the randomly generated client)
to this TCP disconnection process is completed 4 times waved

Guess you like

Origin www.cnblogs.com/zhangdadayou/p/11415389.html