zoukankan      html  css  js  c++  java
  • 读书笔记 ~ 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

  • 相关阅读:
    AJAX 跨域请求与 JSONP详解
    深入理解PHP的mvc框架
    读文文件md5值
    快速排序
    编写简单GUI程序
    简单的加减法
    rallway.py
    用列表构建栈结构
    模拟用户登陆注册
    密码生成
  • 原文地址:https://www.cnblogs.com/Hi-blog/p/7092655.html
Copyright © 2011-2022 走看看