• python+flask


    因为实验室的电脑偶尔会需要跑程序,我在寝室想知道它跑了多少,于是做了这样一个小demo。

    因为寝室与实验室都是一条校园网上的,因此ip上不会有啥问题,甚至之前我也常用python的小服务器传文件。

    这个demo的功能就是在接到访问请求的时候能够给屏幕截一张图,然后显示在网页上。

    用了一点点小手段来避免谁都可以查看我机器的截图,我知道这样也不安全,但是多数情况下,就还好。

    #!usr/bin/python
    
    from flask import Flask
    from PIL import ImageGrab
    import sys
    import time
    
    def PrtSc():
        im = ImageGrab.grab()
        filename = str(time.time()) + '.jpg'
        im.save(sys.path[0] + '\static\' + filename)
        return filename
    
    app = Flask(__name__, static_folder='', static_url_path='')
    
    @app.route("/<pwd>")
    def show_image(pwd):
        correct_pwd = str(time.localtime().tm_hour)+str(time.localtime().tm_min)
        if pwd == correct_pwd:    
            filename = PrtSc()
            return "<html><head></head><body><img src='./static/" + filename + "'></body></html>"
        else:
            return("Hello World!")
        
    
    @app.route("/")
    def hello():
        return("Hello World!")
    
    if __name__ == "__main__":
        app.run(host = '0.0.0.0')

    访问的密码呢,就是当前时间的小时与分钟,还是挺简单的,程序是差不多一个晚上的时间划拉出来的,留个记录就好了。

  • 相关阅读:
    Runtime类
    使用序列化和对象流实现对象的序列化
    Object类
    ThreadLocal
    Java Inner Class 内部类
    css中的:before与:after的简单使用
    JS事件(事件冒泡和事件捕获)
    js call apply bind简单的理解
    JS创建对象
    apache common-io.jar FileUtils
  • 原文地址:https://www.cnblogs.com/ippfcox/p/7092607.html
Copyright © 2020-2023  润新知