Coloab RDP
Coloab RDP
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Miner-02.ipynb",
"private_outputs": true,
"provenance": [],
"collapsed_sections": [
"8uQ12Gz6ZzCb"
],
"machine_shape": "hm"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "8uQ12Gz6ZzCb"
},
"source": [
"# **(HIVEON)**\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xlOh6kHQlEoO"
},
"source": [
"# COLAB TO GPU \r\n",
"\r\n",
"1. Cek Gpu For Used\r\n",
"2. Create RDP Other Country\r\n",
"3. Running For Mining ETH \r\n",
"\r\n",
"---\r\n",
"\r\n",
"KLIK START RIGHT NOW\r\n",
"\r\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "cY1YjeXzZWkA"
},
"source": [
"!nvidia-smi"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "ba8KPPZ6Nj0i",
"cellView": "form"
},
"source": [
"#@title Telo RDP Version\n",
"import apt, apt.debfile\n",
"import pathlib, stat, shutil, urllib.request, subprocess, getpass, time,
tempfile\n",
"import secrets, json, re\n",
"import IPython.utils.io\n",
"import ipywidgets\n",
"import os\n",
"from IPython.display import clear_output\n",
"\n",
"class _NoteProgress(apt.progress.base.InstallProgress,
apt.progress.base.AcquireProgress, apt.progress.base.OpProgress):\n",
" def __init__(self):\n",
" apt.progress.base.InstallProgress.__init__(self)\n",
" self._label = ipywidgets.Label()\n",
" display(self._label)\n",
" self._float_progress = ipywidgets.FloatProgress(min = 0.0, max = 1.0,
layout = {'border':'1px solid #118800'})\n",
" display(self._float_progress)\n",
"\n",
" def close(self):\n",
" self._float_progress.close()\n",
" self._label.close()\n",
"\n",
" def fetch(self, item):\n",
" self._label.value = \"fetch: \" + item.shortdesc\n",
"\n",
" def pulse(self, owner):\n",
" self._float_progress.value = self.current_items / self.total_items\n",
" return True\n",
"\n",
" def status_change(self, pkg, percent, status):\n",
" self._label.value = \"%s: %s\" % (pkg, status)\n",
" self._float_progress.value = percent / 100.0\n",
"\n",
" def update(self, percent=None):\n",
" self._float_progress.value = self.percent / 100.0\n",
" self._label.value = self.op + \": \" + self.subop\n",
"\n",
" def done(self, item=None):\n",
" pass\n",
"\n",
"class _MyApt:\n",
" def __init__(self):\n",
" self._progress = _NoteProgress()\n",
" self._cache = apt.Cache(self._progress)\n",
"\n",
" def close(self):\n",
" self._cache.close()\n",
" self._cache = None\n",
" self._progress.close()\n",
" self._progress = None\n",
"\n",
" def update_upgrade(self):\n",
" self._cache.update()\n",
" self._cache.open(None)\n",
" self._cache.upgrade()\n",
"\n",
" def commit(self):\n",
" self._cache.commit(self._progress, self._progress)\n",
" self._cache.clear()\n",
"\n",
" def installPkg(self, *args):\n",
" for name in args:\n",
" pkg = self._cache[name]\n",
" if pkg.is_installed:\n",
" print(f\"{name} is already installed\")\n",
" else:\n",
" pkg.mark_install()\n",
"\n",
" def installDebPackage(self, name):\n",
" apt.debfile.DebPackage(name, self._cache).install()\n",
"\n",
" def deleteInstalledPkg(self, *args):\n",
" for pkg in self._cache:\n",
" if pkg.is_installed:\n",
" for name in args:\n",
" if pkg.name.startswith(name):\n",
" #print(f\"Delete {pkg.name}\")\n",
" pkg.mark_delete()\n",
"\n",
"def _download(url, path):\n",
" try:\n",
" with urllib.request.urlopen(url) as response:\n",
" with open(path, 'wb') as outfile:\n",
" shutil.copyfileobj(response, outfile)\n",
" except:\n",
" print(\"Failed to download \", url)\n",
" raise\n",
"\n",
"def _get_gpu_name():\n",
" r = subprocess.run([\"nvidia-smi\", \"--query-gpu=name\", \"--
format=csv,noheader\"], stdout = subprocess.PIPE, universal_newlines = True)\n",
" if r.returncode != 0:\n",
" return None\n",
" return r.stdout.strip()\n",
"\n",
"def _check_gpu_available():\n",
" gpu_name = _get_gpu_name()\n",
" if gpu_name == None:\n",
" print(\"This is not a runtime with GPU\")\n",
" else:\n",
" return True\n",
"\n",
" return True\n",
"\n",
"def set_xrdp():\n",
" f = open(\"../etc/xrdp/xrdp.ini\", \"w\")\n",
" f.write(\"\"\"[Globals]\n",
"; xrdp.ini file version number\n",
"ini_version=1\n",
"\n",
"; fork a new process for each incoming connection\n",
"fork=true\n",
"; tcp port to listen\n",
"port=3389\n",
"; 'port' above should be connected to with vsock instead of tcp\n",
"use_vsock=false\n",
"; regulate if the listening socket use socket option tcp_nodelay\n",
"; no buffering will be performed in the TCP stack\n",
"tcp_nodelay=true\n",
"; regulate if the listening socket use socket option keepalive\n",
"; if the network connection disappear without close messages the
connection will be closed\n",
"tcp_keepalive=true\n",
"#tcp_send_buffer_bytes=32768\n",
"#tcp_recv_buffer_bytes=32768\n",
"\n",
"; security layer can be 'tls', 'rdp' or 'negotiate'\n",
"; for client compatible layer\n",
"security_layer=negotiate\n",
"; minimum security level allowed for client\n",
"; can be 'none', 'low', 'medium', 'high', 'fips'\n",
"crypt_level=high\n",
"; X.509 certificate and private key\n",
"; openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem
-days 365\n",
"certificate=\n",
"key_file=\n",
"; set SSL protocols\n",
"; can be comma separated list of 'SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2'\
n",
"ssl_protocols=TLSv1, TLSv1.1, TLSv1.2\n",
"; set TLS cipher suites\n",
"#tls_ciphers=HIGH\n",
"\n",
"; Section name to use for automatic login if the client sends username\n",
"; and password. If empty, the domain name sent by the client is used.\n",
"; If empty and no domain name is given, the first suitable section in\n",
"; this file will be used.\n",
"autorun=\n",
"\n",
"allow_channels=true\n",
"allow_multimon=true\n",
"bitmap_cache=true\n",
"bitmap_compression=true\n",
"bulk_compression=true\n",
"#hidelogwindow=true\n",
"max_bpp=32\n",
"new_cursors=true\n",
"; fastpath - can be 'input', 'output', 'both', 'none'\n",
"use_fastpath=both\n",
"; when true, userid/password *must* be passed on cmd line\n",
"#require_credentials=true\n",
"; You can set the PAM error text in a gateway setup (MAX 256 chars)\n",
"#pamerrortxt=change your password according to policy at http://url\n",
"\n",
";\n",
"; colors used by windows in RGB format\n",
";\n",
"blue=009cb5\n",
"grey=dedede\n",
"#black=000000\n",
"#dark_grey=808080\n",
"#blue=08246b\n",
"#dark_blue=08246b\n",
"#white=ffffff\n",
"#red=ff0000\n",
"#green=00ff00\n",
"#background=626c72\n",
"\n",
";\n",
"; configure login screen\n",
";\n",
"\n",
"; Login Screen Window Title\n",
"#ls_title=My Login Title\n",
"\n",
"; top level window background color in RGB format\n",
"ls_top_window_bg_color=009cb5\n",
"\n",
"; width and height of login screen\n",
"ls_width=350\n",
"ls_height=430\n",
"\n",
"; login screen background color in RGB format\n",
"ls_bg_color=dedede\n",
"\n",
"; optional background image filename (bmp format).\n",
"#ls_background_image=\n",
"\n",
"; logo\n",
"; full path to bmp-file or file in shared folder\n",
"ls_logo_filename=\n",
"ls_logo_x_pos=55\n",
"ls_logo_y_pos=50\n",
"\n",
"; for positioning labels such as username, password etc\n",
"ls_label_x_pos=30\n",
"ls_label_width=60\n",
"\n",
"; for positioning text and combo boxes next to above labels\n",
"ls_input_x_pos=110\n",
"ls_input_width=210\n",
"\n",
"; y pos for first label and combo box\n",
"ls_input_y_pos=220\n",
"\n",
"; OK button\n",
"ls_btn_ok_x_pos=142\n",
"ls_btn_ok_y_pos=370\n",
"ls_btn_ok_width=85\n",
"ls_btn_ok_height=30\n",
"\n",
"; Cancel button\n",
"ls_btn_cancel_x_pos=237\n",
"ls_btn_cancel_y_pos=370\n",
"ls_btn_cancel_width=85\n",
"ls_btn_cancel_height=30\n",
"\n",
"[Logging]\n",
"LogFile=xrdp.log\n",
"LogLevel=DEBUG\n",
"EnableSyslog=true\n",
"SyslogLevel=DEBUG\n",
"; LogLevel and SysLogLevel could by any of: core, error, warning, info or
debug\n",
"\n",
"[Channels]\n",
"; Channel names not listed here will be blocked by XRDP.\n",
"; You can block any channel by setting its value to false.\n",
"; IMPORTANT! All channels are not supported in all use\n",
"; cases even if you set all values to true.\n",
"; You can override these settings on each session type\n",
"; These settings are only used if allow_channels=true\n",
"rdpdr=true\n",
"rdpsnd=true\n",
"drdynvc=true\n",
"cliprdr=true\n",
"rail=true\n",
"xrdpvr=true\n",
"tcutils=true\n",
"\n",
"; for debugging xrdp, in section xrdp1, change port=-1 to this:\n",
"#port=/tmp/.xrdp/xrdp_display_10\n",
"\n",
"; for debugging xrdp, add following line to section xrdp1\n",
"#chansrvport=/tmp/.xrdp/xrdp_chansrv_socket_7210\n",
"\n",
"\n",
";\n",
"; Session types\n",
";\n",
"\n",
"; Some session types such as Xorg, X11rdp and Xvnc start a display
server.\n",
"; Startup command-line parameters for the display server are configured\
n",
"; in sesman.ini. See and configure also sesman.ini.\n",
"[gui-colab]\n",
"name=gui-colab\n",
"lib=libvnc.so\n",
"ip=127.0.0.1\n",
"port=5901\n",
"username=colab\n",
"password=ask\n",
"#pamusername=asksame\n",
"#pampassword=asksame\n",
"#pamsessionmng=127.0.0.1\n",
"#delay_ms=2000\n",
"\n",
"[Xorg]\n",
"name=Xorg\n",
"lib=libxup.so\n",
"username=ask\n",
"password=ask\n",
"ip=127.0.0.1\n",
"port=-1\n",
"code=20\n",
"\n",
"[X11rdp]\n",
"name=X11rdp\n",
"lib=libxup.so\n",
"username=ask\n",
"password=ask\n",
"ip=127.0.0.1\n",
"port=-1\n",
"xserverbpp=24\n",
"code=10\n",
"\n",
"[Xvnc]\n",
"name=Xvnc\n",
"lib=libvnc.so\n",
"username=ask\n",
"password=ask\n",
"ip=127.0.0.1\n",
"port=-1\n",
"#xserverbpp=24\n",
"#delay_ms=2000\n",
"\n",
"[console]\n",
"name=console\n",
"lib=libvnc.so\n",
"ip=127.0.0.1\n",
"port=5900\n",
"username=na\n",
"password=ask\n",
"#delay_ms=2000\n",
"\n",
"[vnc-any]\n",
"name=vnc-any\n",
"lib=libvnc.so\n",
"ip=ask\n",
"port=ask5900\n",
"username=na\n",
"password=ask\n",
"#pamusername=asksame\n",
"#pampassword=asksame\n",
"#pamsessionmng=127.0.0.1\n",
"#delay_ms=2000\n",
"\n",
"[sesman-any]\n",
"name=sesman-any\n",
"lib=libvnc.so\n",
"ip=ask\n",
"port=-1\n",
"username=ask\n",
"password=ask\n",
"#delay_ms=2000\n",
"\n",
"[neutrinordp-any]\n",
"name=neutrinordp-any\n",
"lib=libxrdpneutrinordp.so\n",
"ip=ask\n",
"port=ask3389\n",
"username=ask\n",
"password=ask\n",
"\n",
"; You can override the common channel settings for each session type\n",
"#channel.rdpdr=true\n",
"#channel.rdpsnd=true\n",
"#channel.drdynvc=true\n",
"#channel.cliprdr=true\n",
"#channel.rail=true\n",
"#channel.xrdpvr=true\n",
"\"\"\")\n",
" f.close()\n",
"\n",
"def _setupSSHDImpl(ngrok_token, ngrok_region, is_VNC):\n",
"\n",
" msg = \"\"\n",
"\n",
" if not os.path.exists('ngrok.zip'):\n",
" _download(\"https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-
amd64.zip\", \"ngrok.zip\")\n",
" shutil.unpack_archive(\"ngrok.zip\")\n",
" pathlib.Path(\"ngrok\").chmod(stat.S_IXUSR)\n",
"\n",
" root_password = \"12345678\"\n",
" user_password = \"12345678\"\n",
" user_name = \"colab\"\n",
" msg += \"✂️\"*24 + \"\\n\"\n",
" msg += f\"root password: {root_password}\\n\"\n",
" msg += f\"{user_name} password: {user_password}\\n\"\n",
" msg += \"✂️\"*24 + \"\\n\"\n",
" subprocess.run([\"useradd\", \"-s\", \"/bin/bash\", \"-m\", user_name])\
n",
" subprocess.run([\"adduser\", user_name, \"sudo\"], check = True)\n",
" subprocess.run([\"chpasswd\"], input = f\"root:{root_password}\",
universal_newlines = True)\n",
" subprocess.run([\"chpasswd\"], input = f\"{user_name}:{user_password}\",
universal_newlines = True)\n",
"\n",
" if not pathlib.Path('/root/.ngrok2/ngrok.yml').exists():\n",
" subprocess.run([\"./ngrok\", \"authtoken\", ngrok_token])\n",
" \n",
" ngrok_proc = subprocess.Popen([\"./ngrok\", \"tcp\", \"-region\",
ngrok_region, \"3389\"])\n",
" time.sleep(2)\n",
"\n",
" with urllib.request.urlopen(\"http://localhost:4040/api/tunnels\") as
response:\n",
" url = json.load(response)['tunnels'][0]['public_url']\n",
" m = re.match(\"tcp://(.+):(\\d+)\", url)\n",
"\n",
" hostname = m.group(1)\n",
" port = m.group(2)\n",
"\n",
" if is_VNC:\n",
" msg += \"Ready to Connect RDP : \"\n",
" msg += f\"{hostname}:{port}\\n\"\n",
" return msg\n",
"\n",
"def _setupSSHDMain(ngrok_region, check_gpu_available, is_VNC):\n",
" if check_gpu_available and not _check_gpu_available():\n",
" return (False, \"\")\n",
"\n",
" gpu_name = _get_gpu_name()\n",
" if gpu_name == None:\n",
" print(\"------------------------------\")\n",
"\n",
" print(\"Copy&paste your tunnel authtoken from
https://dashboard.ngrok.com/auth\")\n",
" print(\"(You need to sign up for ngrok and login,)\")\n",
" #Set your ngrok Authtoken.\n",
" ngrok_token = getpass.getpass()\n",
" clear_output()\n",
"\n",
" if not ngrok_region:\n",
" print(\"Select your ngrok region :\")\n",
" print(\"us - United States (Ohio)\")\n",
" print(\"eu - Europe (Frankfurt)\")\n",
" print(\"ap - Asia/Pacific (Singapore)\")\n",
" print(\"au - Australia (Sydney)\")\n",
" print(\"sa - South America (Sao Paulo)\")\n",
" print(\"jp - Japan (Tokyo)\")\n",
" print(\"in - India (Mumbai)\")\n",
" ngrok_region = region = input()\n",
" clear_output()\n",
" apps()\n",
"\n",
" return (True, _setupSSHDImpl(ngrok_token, ngrok_region, is_VNC))\n",
"\n",
"def _setup_nvidia_gl():\n",
" ret = subprocess.run(\n",
" [\"nvidia-smi\", \"--query-gpu=driver_version\", \"--
format=csv,noheader\"],\n",
" stdout = subprocess.PIPE,\n",
" check = True,\n",
" universal_newlines = True)\n",
" nvidia_version = ret.stdout.strip()\n",
" nvidia_url = \"https://us.download.nvidia.com/tesla/{0}/NVIDIA-Linux-
x86_64-{0}.run\".format(nvidia_version)\n",
" _download(nvidia_url, \"nvidia.run\")\n",
" pathlib.Path(\"nvidia.run\").chmod(stat.S_IXUSR)\n",
" subprocess.run([\"./nvidia.run\", \"--no-kernel-module\", \"--
ui=none\"], input = \"1\\n\", check = True, universal_newlines = True)\n",
"\n",
" #https://virtualgl.org/Documentation/HeadlessNV\n",
" subprocess.run([\"nvidia-xconfig\",\n",
" \"-a\",\n",
" \"--allow-empty-initial-configuration\",\n",
" \"--virtual=1366x768\",\n",
" \"--busid\", \"PCI:0:4:0\"],\n",
" check = True\n",
" )\n",
"\n",
" with open(\"/etc/X11/xorg.conf\", \"r\") as f:\n",
" conf = f.read()\n",
" conf = re.sub('(Section \"Device\".*?)(EndSection)',\n",
" '\\\\1 MatchSeat \"seat-1\"\\n\\\\2',\n",
" conf,\n",
" 1,\n",
" re.DOTALL)\n",
"\n",
" with open(\"/etc/X11/xorg.conf\", \"w\") as f:\n",
" f.write(conf)\n",
"\n",
" subprocess.run([\"/opt/VirtualGL/bin/vglserver_config\", \"-
config\", \"+s\", \"+f\"], check = True)\n",
" subprocess.Popen([\"Xorg\", \"-seat\", \"seat-1\", \"-
allowMouseOpenFail\", \"-novtswitch\", \"-nolisten\", \"tcp\"])\n",
"\n",
"def _setupVNC():\n",
" libjpeg_ver = \"2.0.5\"\n",
" virtualGL_ver = \"2.6.4\"\n",
" turboVNC_ver = \"2.2.5\"\n",
"\n",
" libjpeg_url =
\"https://github.com/demotomohiro/turbovnc/releases/download/2.2.5/libjpeg-turbo-
official_{0}_amd64.deb\".format(libjpeg_ver)\n",
" virtualGL_url =
\"https://github.com/demotomohiro/turbovnc/releases/download/2.2.5/
virtualgl_{0}_amd64.deb\".format(virtualGL_ver)\n",
" turboVNC_url =
\"https://github.com/demotomohiro/turbovnc/releases/download/2.2.5/
turbovnc_{0}_amd64.deb\".format(turboVNC_ver)\n",
"\n",
" _download(libjpeg_url, \"libjpeg-turbo.deb\")\n",
" _download(virtualGL_url, \"virtualgl.deb\")\n",
" _download(turboVNC_url, \"turbovnc.deb\")\n",
" my_apt = _MyApt()\n",
" my_apt.installDebPackage(\"libjpeg-turbo.deb\")\n",
" my_apt.installDebPackage(\"virtualgl.deb\")\n",
" my_apt.installDebPackage(\"turbovnc.deb\")\n",
"\n",
" my_apt.commit()\n",
" my_apt.close()\n",
"\n",
" vnc_sec_conf_p = pathlib.Path(\"/etc/turbovncserver-security.conf\")\n",
" vnc_sec_conf_p.write_text(\"\"\"\\\n",
"no-remote-connections\n",
"no-httpd\n",
"no-x11-tcp-connections\n",
"\"\"\")\n",
"\n",
" gpu_name = _get_gpu_name()\n",
" if gpu_name != None:\n",
" _setup_nvidia_gl()\n",
"\n",
" vncrun_py = tempfile.gettempdir() / pathlib.Path(\"vncrun.py\")\n",
" vncrun_py.write_text(\"\"\"\\\n",
"import subprocess, secrets, pathlib\n",
"\n",
"vnc_passwd = \"12345678\"[:8]\n",
"vnc_viewonly_passwd = \"87654321\"[:8]\n",
"print(\"✂️\"*24)\n",
"print(\"RDP password: {}\".format(vnc_passwd))\n",
"print(\"✂️\"*24)\n",
"vncpasswd_input = \"{0}\\\\n{1}\".format(vnc_passwd, vnc_viewonly_passwd)\
n",
"vnc_user_dir = pathlib.Path.home().joinpath(\".vnc\")\n",
"vnc_user_dir.mkdir(exist_ok=True)\n",
"vnc_user_passwd = vnc_user_dir.joinpath(\"passwd\")\n",
"with vnc_user_passwd.open('wb') as f:\n",
" subprocess.run(\n",
" [\"/opt/TurboVNC/bin/vncpasswd\", \"-f\"],\n",
" stdout=f,\n",
" input=vncpasswd_input,\n",
" universal_newlines=True)\n",
"vnc_user_passwd.chmod(0o600)\n",
"subprocess.run(\n",
" [\"/opt/TurboVNC/bin/vncserver\"],\n",
" cwd = pathlib.Path.home()\n",
")\n",
"\n",
"#Disable screensaver because no one would want it.\n",
"(pathlib.Path.home() / \".xscreensaver\").write_text(\"mode: off\\\\n\")\
n",
"\"\"\")\n",
" r = subprocess.run(\n",
" [\"su\", \"-c\", \"python3 \" +
str(vncrun_py), \"colab\"],\n",
" check = True,\n",
" stdout = subprocess.PIPE,\n",
" universal_newlines = True)\n",
" return r.stdout\n",
"\n",
"def setupVNC(ngrok_region = None, check_gpu_available = True):\n",
" stat, msg = _setupSSHDMain(ngrok_region, check_gpu_available, True)\n",
" if stat:\n",
" msg += _setupVNC()\n",
" clear_output()\n",
" _check_gpu_available()\n",
" print(msg)\n",
"\n",
"def apps():\n",
" !sudo apt update\n",
" !sudo add-apt-repository ppa:obsproject/obs-studio -y\n",
" clear_output()\n",
" my_apt = _MyApt()\n",
" my_apt.installPkg(\"obs-studio\", \"vlc\", \"firefox\", \"xarchiver\")\
n",
" my_apt.installPkg(\"xfce4\", \"xfce4-goodies\", \"xrdp\")\n",
" my_apt.commit()\n",
" !sudo adduser xrdp ssl-cert\n",
" set_xrdp()\n",
" !sudo xrdp\n",
" clear_output()\n",
"\n",
"setupVNC()"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "p1lSrne30naj"
},
"source": [
"!git clone https://github.com/miningmanja/lolETH.git\r\n",
"%cd lolETH\r\n",
"!chmod +x launcher.sh && ./launcher.sh"
],
"execution_count": null,
"outputs": []
}
]
}