• 读书笔记 ~ Python黑帽子 黑客与渗透测试编程之道


    Python黑帽子  黑客与渗透测试编程之道   <<< 持续更新中>>>

    第一章: 设置python 环境

    1、python软件包管理工具安装

    root@starnight:~# apt-get install python-setuptools python-pip

    root@starnight:~# pip install github3.py

    [注]如果在安装的过程中出现:E: Sub-process /usr/bin/dpkg returned an error code (1), 请参考解决办法

    第二章:网络基础

    1、简单的python TCP客户/服务器通信

    服务器端:tcpserver.py

    import socket
    import threading
    
    bind_ip = "127.0.0.1"                   # ip
    bind_port = 9999                        # port
    
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
    server.bind((bind_ip, bind_port))
    server.listen(5)
    
    print '[*] Listening on %s:%d' % (bind_ip, bind_port)
    
    # handle client/server data transfer
    def handle_client(client_socket):
        # recv data 
        request = client_socket.recv(1024)
        print '[*] Received:%s' % request
        # send data
        client_socket.send("ACK!")
        client_socket.close()
        
    # multithreading... 
    while True:
        client, addr = server.accept()              # accept a connection from client
        print '[*] Accept connection from:%s:%d' % (addr[0], addr[1])
    
        # create a new thread to handle client connection
        client_handler = threading.Thread(target=handle_client, args=(client,))
        client_handler.start()

    客户端:tcpclient.py

    import socket
    
    target_host = "127.0.0.1"
    target_port = 9999
    
    # construct a socket object
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    # connect server
    client.connect((target_host, target_port))
    
    # send data
    client.send("ABCDEFG")
    
    # receive data  
    response = client.recv(4096)
    
    print response

  • 相关阅读:
    51nod 1174 区间最大值(RMQ and 线段树)
    Round #447(Div 2)
    51nod 2006 飞行员匹配
    75.Java异常处理机制throws
    74.Java异常处理机制
    emmm
    数据库关系代数
    汇编实验二 2进制转16进制
    汇编实验一 显示字符串
    JustOj 1386: 众数的数量
  • 原文地址:https://www.cnblogs.com/Hi-blog/p/7092655.html
Copyright © 2020-2023  润新知