Network security-python C/S-based programming and network security-python
1. socket programming
Socket types include:
-- TCP socket and UDP socket.
- Regular customer service mode.
-- Raw socket
- Used for sniffing and injection
2. C/S Mode
The C/S (Client/Server, Client/Server) mode, also known as the C/S structure, is a model that gradually grew up at the end of 1980s and is a kind of software system architecture. The key to the C/S structure is the distribution of functions. Some functions are executed on the front-end machine (client), while others are executed on the backend machine (server.
3. python c/s programming
Server code:
#! /Usr/bin/env python # _ * _ coding: UTF-8 _ * _ import sockettcpSock = socket. socket (socket. AF_INET, socket. SOCK_STREAM) tcpSock. bind ("0.0.0.0", 8080) tcpSock. listen (5) print 'Wait for the client to connect ...... '(client, (ip, sock) = tcpSock. accept () print 'creates a connection, and the IP address of the other party is', ipprint 'starts to receive data ...... 'Data = 'start' while len (data): data = client. recv (2048) print 'Received data: ', data client. send ('Return data: '+ data) print' closes the connection ...... 'client. close () print 'close the service ...... 'tcpsock. close ()
Run the python program on the server and run the following command to test the program:
nc 192.168.1.95 8080
Server Response:
Client test:
4. client-specific options
- Processing in sequence
- Multi-thread Server
- Multi-process server
- Non-blocking socket (use select)