|
| 1 | +from flask import Flask, Response, render_template |
| 2 | +from io import BytesIO |
| 3 | +from PIL import ImageGrab |
| 4 | +import logging |
| 5 | +import os |
| 6 | +import sys |
| 7 | +import ifaddr |
| 8 | +import re |
| 9 | + |
| 10 | +base_dir = '.' |
| 11 | +if hasattr(sys, '_MEIPASS'): |
| 12 | + base_dir = os.path.join(sys._MEIPASS) |
| 13 | + |
| 14 | +app = Flask(__name__, |
| 15 | + static_folder=os.path.join(base_dir, 'static'), |
| 16 | + template_folder=os.path.join(base_dir, 'templates')) |
| 17 | + |
| 18 | + |
| 19 | +@app.route('/') |
| 20 | +def index(): |
| 21 | + return render_template('index.html') |
| 22 | + |
| 23 | + |
| 24 | +@app.route('/feed') |
| 25 | +def video_feed(): |
| 26 | + return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame') |
| 27 | + |
| 28 | + |
| 29 | +def gen(): |
| 30 | + while True: |
| 31 | + img_buffer = BytesIO() |
| 32 | + ImageGrab.grab().save(img_buffer, 'JPEG', quality=50) |
| 33 | + img_buffer.seek(0) |
| 34 | + yield (b'--frame\r\n' |
| 35 | + b'Content-Type: image/jpg\r\n\r\n' + img_buffer.read() + b'\r\n\r\n') |
| 36 | + |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + def get_v4(ip, adapter): |
| 40 | + if re.match(r"^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$", ip): |
| 41 | + print(f'• Sharing screen on ip => http://{ip}:6999 \tof "{adapter}"') |
| 42 | + |
| 43 | + |
| 44 | + cli = sys.modules['flask.cli'] |
| 45 | + cli.show_server_banner = lambda *x: None |
| 46 | + cli = lambda *x: None |
| 47 | + log = logging.getLogger('werkzeug') |
| 48 | + log.setLevel(logging.ERROR) |
| 49 | + |
| 50 | + APP_TITLE = """ |
| 51 | + |
| 52 | +
|
| 53 | + .----------------. .----------------. .----------------. .----------------. .----------------. .-----------------. |
| 54 | +| .--------------. | .--------------. | .--------------. | .--------------. | .--------------. | .--------------. | |
| 55 | +| | _______ | | | ______ | | | _______ | | | _________ | | | _________ | | | ____ _____ | | |
| 56 | +| | / ___ | | | | .' ___ | | | | |_ __ \ | | | |_ ___ | | | | |_ ___ | | | ||_ \|_ _| | | |
| 57 | +| | | (__ \_| | | | / .' \_| | | | | |__) | | | | | |_ \_| | | | | |_ \_| | | | | \ | | | | |
| 58 | +| | '.___`-. | | | | | | | | | __ / | | | | _| _ | | | | _| _ | | | | |\ \| | | | |
| 59 | +| | |`\____) | | | | \ `.___.'\ | | | _| | \ \_ | | | _| |___/ | | | | _| |___/ | | | | _| |_\ |_ | | |
| 60 | +| | |_______.' | | | `._____.' | | | |____| |___| | | | |_________| | | | |_________| | | ||_____|\____| | | |
| 61 | +| | | | | | | | | | | | | | | | | | | |
| 62 | +| '--------------' | '--------------' | '--------------' | '--------------' | '--------------' | '--------------' | |
| 63 | + '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' |
| 64 | + .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. |
| 65 | +| .--------------. | .--------------. | .--------------. | .--------------. | .--------------. | .--------------. | |
| 66 | +| | ______ | | | __ | | | _______ | | | _________ | | | _________ | | | _______ | | |
| 67 | +| | .' ___ | | | | / \ | | | / ___ | | | | | _ _ | | | | |_ ___ | | | | |_ __ \ | | |
| 68 | +| | / .' \_| | | | / /\ \ | | | | (__ \_| | | | |_/ | | \_| | | | | |_ \_| | | | | |__) | | | |
| 69 | +| | | | | | | / ____ \ | | | '.___`-. | | | | | | | | | _| _ | | | | __ / | | |
| 70 | +| | \ `.___.'\ | | | _/ / \ \_ | | | |`\____) | | | | _| |_ | | | _| |___/ | | | | _| | \ \_ | | |
| 71 | +| | `._____.' | | ||____| |____|| | | |_______.' | | | |_____| | | | |_________| | | | |____| |___| | | |
| 72 | +| | | | | | | | | | | | | | | | | | | |
| 73 | +| '--------------' | '--------------' | '--------------' | '--------------' | '--------------' | '--------------' | |
| 74 | + '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + """ |
| 80 | + print(APP_TITLE) |
| 81 | + network_adapters = ifaddr.get_adapters() |
| 82 | + |
| 83 | + for adapter in network_adapters: |
| 84 | + for ip in adapter.ips: |
| 85 | + get_v4(str(ip.ip), str(adapter.nice_name)) |
| 86 | + print('\n** (Press CTRL+C) to stop screen share') |
| 87 | + app.run(host='0.0.0.0', port=6999, debug=False) |
0 commit comments