Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- import subprocess
- import sys
- import time
- # Python3 console app to both run , install vnc server and ssh server , start , stop and exit
- # futher introduced was capture the output and print to screen I think you will love the way this done
- # MD Harrington date 25-05-2023 time 10:35 AM this took some time to work this all out
- # For the benefit of some friends on face book and instagram
- # This is how its done
- class Menu:
- def __init__(self):
- os.system("clear")
- self.choices = {
- "1": self.check_install_x11vnc_server,
- "2": self.check_install_ssh_server,
- "3": self.start_vnc_server,
- "4": self.stop_vnc_server,
- "0": self.exit_menu
- }
- def typewriter_print(self, text, color=""):
- for char in text:
- sys.stdout.write("{}{}".format(color, char))
- sys.stdout.flush()
- time.sleep(0.02)
- print("\033[0m")
- def display_menu(self):
- self.typewriter_print("\033[1;36m------ Menu ------")
- self.typewriter_print("1. \033[1;35mCheck and install X11VNC server")
- self.typewriter_print("2. \033[1;34mCheck and install SSH server")
- self.typewriter_print("3. \033[1;33mStart VNC server")
- self.typewriter_print("4. \033[1;32mStop VNC server")
- self.typewriter_print("0. \033[1;31mExit")
- def check_install_x11vnc_server(self):
- self.typewriter_print("\033[1;33mChecking X11VNC server...\033[0m")
- result = subprocess.run(["which", "x11vnc"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
- if result.returncode != 0:
- self.typewriter_print("\033[1;31mX11VNC server not found. Installing...\033[0m")
- os.system("sudo apt install -y x11vnc")
- else:
- self.typewriter_print("\033[1;32mX11VNC server is installed.\033[0m")
- def check_install_ssh_server(self):
- self.typewriter_print("\033[1;33mChecking SSH server...\033[0m")
- ##########################################################################################################
- # Alteration made to the line below 15:39hrs 23-05-2023 removed 3rd argument "--quiet" Now detects sshd#
- ##########################################################################################################
- result = subprocess.run(["systemctl", "is-active", "ssh"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
- if result.returncode != 0:
- self.typewriter_print("\033[1;31mSSH server not found. Installing and starting...\033[0m")
- os.system("sudo apt install -y openssh-server")
- os.system("sudo systemctl enable ssh")
- os.system("sudo systemctl start ssh")
- else:
- self.typewriter_print("\033[1;32mSSH server is installed and running.\033[0m")
- def start_vnc_server(self):
- self.typewriter_print("\033[1;33mStarting VNC server...\033[0m")
- os.system("x11vnc -auth guess -forever -rfbauth $HOME/.vnc/passwd -rfbport 5900 -shared")
- def stop_vnc_server(self):
- self.typewriter_print("\033[1;33mStopping VNC server...\033[0m")
- os.system("x11vnc -R stop")
- def exit_menu(self):
- self.typewriter_print("\033[1;33mExiting menu...\033[0m")
- time.sleep(1)
- os.system("clear")
- sys.exit()
- def run(self):
- while True:
- self.display_menu()
- choice = input("Enter your choice: ")
- action = self.choices.get(choice)
- if action:
- action()
- time.sleep(1)
- input("\nPress Enter to continue...")
- os.system("clear")
- def main():
- menu = Menu()
- menu.run()
- if __name__ == "__main__":
- Menu.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement