zoukankan      html  css  js  c++  java
  • 实现简单的ssh功能

    客户端代码:

    # -*- coding=utf-8 -*-

    __Author__ = "Dennis"

    import socket

    client = socket.socket()

    client.connect(("localhost",6969))


    while True:
    msg = input(">> ")
    if not msg:continue
    client.send(msg.encode())
    data_size = client.recv(1024)
    print("Will Size:",data_size)
    true_size = int(data_size.decode())
    client.send(b"recieve")
    receive_size = 0
    while receive_size < true_size:
    data = client.recv(1024)
    receive_size += len(data)
    print(data.decode())
    print("Size:",receive_size)

    client.close()



    服务端代码
    # -*- coding=utf-8 -*-


    __Author__ = 'Dennis'


    import socket,os

    server = socket.socket()
    server.bind(("localhost",6969))
    server.listen(5)

    print("等电话...")
    conn,addr = server.accept()
    print("电话来啦。。")
    while True:
    data = conn.recv(1024)
    if not data:
    print("client has lost")
    break
    print("Command: ",data)
    res_msg = os.popen(data.decode()).read()
    res_msg_b = res_msg.encode()
    res_size = len(res_msg_b)
    conn.send(str(res_size).encode())
    is_true = conn.recv(1024)
    conn.send(res_msg_b)
    server.close()
  • 相关阅读:
    求第N个素数
    HDU1568
    HDU1003 DP
    POJ 1016 模拟字符串
    POJ 3321 树状数组(+dfs+重新建树)
    UVA12532 线段树(单点更新,区间求乘积的正负)
    POJ2488 dfs
    POJ 1195 二维树状数组
    HDU 4006 优先队列
    优先队列
  • 原文地址:https://www.cnblogs.com/dennnnnis/p/7423101.html
Copyright © 2011-2022 走看看