Python c/S mode BASIC programming for network security

Source: Internet
Author: User

1. Socket programming

Socket types include:

--TCP socket and UDP socket.

    • The General Customer service Area mode.

--raw socket

    • Can be used for sniffing and injecting
2. C/S mode

c/S (client/server, client/server) mode, also known as C/s structure, is a model that grew up in the the late 1980s and is a kind of software system architecture. The key of C/s structure lies in the distribution of functions, some functions are performed on the front end machine (i.e. client), and some functions are placed on the backend machine (i.e. server).
  

3.python C/S programming

Server Section Code:
  

#!/usr/bin/env python# _*_ Coding:utf-8 _*_ImportSocketTcpsock =Socket.Socket(Socket. Af_inet,Socket. SOCK_STREAM) Tcpsock.Bind(("0.0.0.0",8080)) Tcpsock.Listen(5)Print ' Waiting for client connections ... '(Client, (ip,sock)) = Tcpsock.Accept()Print ' Set up a connection, the other IP is: 'IpPrint ' Start receiving data ... 'data =' Start ' whileLen (data): data = client.recv(2048)Print ' received data: ', data client.Send(' return data: '+data)Print ' Close connection ... 'Client.Close()Print ' Close service ... 'Tcpsock.Close()

Run the server-side Python program and test it with a command:

nc192.168.1.958080

Server response:

Client test:

4. Options for the client
    • Processed sequentially
    • Multi-Threaded Server
    • Multi-Process Server
    • Non-blocking mode socket (using Select)

Python c/S mode BASIC programming for network security

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.