from flask import Flask, request import webbrowser import os import re app = Flask(__name__) @app.route('/mycomp', methods=['POST']) def hell(): json_string = request.json if json_string['command'] == 'test': return 'The server is running and waiting for commands...' if json_string['command'] == 'openweb': webbrowser.open(url='https://www.'+json_string['data'], new=0) return 'Site opening ' + json_string['data'] + '...' if json_string['command'] == 'shell': os.system(json_string['data']) return 'Command execution ' + json_string['data'] + '...' if json_string['command'] == 'link': links = open('links.txt', 'r') for i in range(int(json_string['data'])): link = links.readline() os.system(link.split('>')[0]) return 'Launch ' + link.split('>')[1] if __name__ == '__main__': app.run(host='0.0.0.0')
{'command': 'comecommand', 'data': 'somedata'}
import requests logo = ['\n\n', '****** ********', '******* *********', '** ** ** **', '** ** ** ** Written on Python', '******* ** **', '******** ** **', '** ** ** ** Author: ROBOTD4', '** ** ** **', '** ** ** **', '******** *********', '******* ********', '\n\n'] p = '' iport = '192.168.1.2:5000' host = 'http://' + iport + '/mycomp' def test(): dict = {'command': 'test', 'data': 0} r = requests.post(host, json=dict) if r.status_code == 200: print (r.content.decode('utf-8')) def start(): for i in logo: print(i) start() test() while True: command = input('>') if command == '': continue a = command.split() if command == 'test': dict = {'command': 'test', 'data': 0} r = requests.post(host, json=dict) if r.status_code == 200: print (r.content.decode('utf-8')) if a[0] == 'shell': for i in range(1, len(a)): p = p + a[i] + ' ' dict = {'command': 'shell', 'data': p} r = requests.post(host, json=dict) if r.status_code == 200: print (r.content.decode('utf-8')) p = '' if a[0] == 'link': if len(a) > 1: dict = {'command': 'link', 'data': int(a[1])} r = requests.post(host, json=dict) if r.status_code == 200: print (r.content.decode('utf-8')) else: print(' !') if a[0] == 'openweb': if len(a) > 1: dict = {'command': 'openweb', 'data': a[1]} r = requests.post(host, json=dict) if r.status_code == 200: print (r.content.decode('utf-8')) else: print(' !') if a[0] == 'set': if a[1] == 'host': ip = a[2] + ':5000' if command == 'quit': break
_>
_>
Source: https://habr.com/ru/post/448360/
All Articles