Network security-python C/S-based programming and network security-python

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.