{"id":16736391,"url":"https://github.com/ritiek/muxnect","last_synced_at":"2025-03-21T21:31:42.914Z","repository":{"id":57444215,"uuid":"115346931","full_name":"ritiek/muxnect","owner":"ritiek","description":"Send input to just about any interactive command-line tool through a local web server","archived":false,"fork":false,"pushed_at":"2019-12-05T10:18:22.000Z","size":43,"stargazers_count":23,"open_issues_count":5,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-10T16:51:55.991Z","etag":null,"topics":["command-line","connect","input","interactive","local","network","send","tmux"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ritiek.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-25T15:21:27.000Z","updated_at":"2021-11-23T10:25:28.000Z","dependencies_parsed_at":"2022-09-26T17:21:23.879Z","dependency_job_id":null,"html_url":"https://github.com/ritiek/muxnect","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fmuxnect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fmuxnect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fmuxnect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fmuxnect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ritiek","download_url":"https://codeload.github.com/ritiek/muxnect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244164571,"owners_count":20408954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","connect","input","interactive","local","network","send","tmux"],"created_at":"2024-10-13T00:22:13.199Z","updated_at":"2025-03-21T21:31:42.552Z","avatar_url":"https://github.com/ritiek.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"muxnect\n=======\n\n|Pypi Version| |Build Status|\n\nSend input to just about any interactive command-line tool through a local\nweb server.\n\nmuxnect is a tool that invokes tmux to create a session and then wraps\naround its method of sending mouse-events or key-strokes to the terminal\nthrough a local web server.\n\nSecurity Note\n-------------\n\nSince there is no way to authenticate at the moment, please use this tool only on systems (and local networks) you completely trust. If an attacker somehow gets to know the URL muxnect is listening on, **nothing stops them from running arbitrary shell commands and completely mess you up.** Please take care!\n\nQuick Introduction\n------------------\n\nA bare-bones method to muxnect any interactive CLI tool:\n\n.. code:: bash\n\n    $ muxnect -w \u003ctmux_window_name\u003e -c \u003csome_interactive_tool\u003e\n\nNow just nail up some POST requests to\nhttp://localhost:6060/muxnect/tmux_window_name\n\nLet's try using Python:\n\n.. code:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e url = 'http://localhost:6060/muxnect/\u003ctmux_window_name\u003e'\n    \u003e\u003e\u003e requests.post(url, data={'keys': 'wonderful keystrokes'})\n    \u003cResponse [200]\u003e\n\nThat's it, our web server just sent ``wonderful keystrokes`` to\n``\u003csome_interactive_tool\u003e``.\n\nExamples\n--------\n\nOkay, that probably left you confused.\n\nHere are some cool examples to cover up:\n\nHello World - Python\n~~~~~~~~~~~~~~~~~~~~\n\nHere we'll print hello world in Python through muxnect.\n\nLet's call muxnect to launch a Python console where it is supposed to\nprint hello world:\n\n.. code:: bash\n\n    $ muxnect -w hello_world -c python\n\nNow hook up another Python console and using it let's send a POST\nrequest to muxnect's server:\n\n.. code:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e url = 'http://localhost:6060/muxnect/hello_world'\n    \u003e\u003e\u003e hello_world = 'print(\"Hello World!\")'\n    # send return key after it is done sending `keys`\n    \u003e\u003e\u003e requests.post(url, data={'keys':hello_world, 'enter':'true'})\n    \u003cResponse [200]\u003e\n\n(of course, you can use any good way to make POST requests and not just\nstay limited to Python requests)\n\nThere's our ``Hello World!`` on the Python console we launched through\nmuxnect.\n\nNow, let's go through the ``separator`` parameter:\n\n.. code:: python\n\n    # send KeyboardInterrupt after sending keys\n    \u003e\u003e\u003e requests.post(url, data={'keys':'send Ctrl+c; C-c', 'separator':'; '})\n    \u003cResponse [200]\u003e\n    # separator will split keys to preserve any special keys\n    # here it will send \"send Ctrl+c\" and then immediately \"C-c\" (Ctrl+c, KBInterrupt)\n    # you can use any number of separator blocks in `keys` param\n\n    # try similar code without using separators\n    \u003e\u003e\u003e requests.post(url, data={'keys':'no Ctrl+c; C-c'})\n    \u003cResponse [200]\u003e\n    # note how it sends raw keys directly\n\n    # send return key and EOF (Ctrl+d) to end our python session\n    \u003e\u003e\u003e requests.post(url, data={'keys':'Enter; C-d', 'separator':'; '})\n    \u003cResponse [200]\u003e\n\nSeparators are helpful when we need to send a combination of\nraw keys and special keys. Without it, the ``key`` param will be\ninterpreted rawly.\n\nFrom the `tmux official docs \u003chttp://man.openbsd.org/OpenBSD-current/man1/tmux.1#KEY_BINDINGS\u003e`__,\nhere are all the special keys that may be used:\n\n    tmux allows a command to be bound to most keys, with or without a prefix key.\n    When specifying keys, most represent themselves (for example ‘A’ to ‘Z’).\n    Ctrl keys may be prefixed with ‘C-’ or ‘^’, and Alt (meta) with ‘M-’.\n    In addition, the following special key names are accepted:\n    Up, Down, Left, Right, BSpace, BTab, DC (Delete), End, Enter, Escape,\n    F1 to F12, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space, and Tab.\n\nWe're done. Exit the running tmux session in muxnect with Ctrl+d.\n\nControl Media Playback\n~~~~~~~~~~~~~~~~~~~~~~\n\nFor a real-world example, let's try controlling media playback in\n`mpv-player \u003chttps://github.com/mpv-player/mpv\u003e`__.\n\nYou can install ``mpv`` from apt if you don't have it already.\n\nLet's play some video though mpv using muxnect:\n\n.. code:: bash\n\n    $ muxnect -w playback -c \"mpv --loop-file https://github.com/mediaelement/mediaelement-files/raw/master/big_buck_bunny.mp4\"\n\nHold on for the video to show up and then we'll send input to this\nrunning instance of mpv:\n\n.. code:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e url = 'http://localhost:6060/muxnect/playback'\n    # space key pauses the video in mpv by default\n    \u003e\u003e\u003e requests.post(url, data={'keys':' '})\n    \u003cResponse [200]\u003e\n    \n    # capture all visible textual content from the tmux pane\n    \u003e\u003e\u003e response = requests.post(url, data={'capture-pane': True})\n    \u003e\u003e\u003e print(response.text)\n    \"\"\"\n    me@hostname:~ $  mpv --loop-file https://github.com/mediaelement/mediaelement-files/raw/master/big_buck_bunny.mp4\n    Playing: https://github.com/mediaelement/mediaelement-files/raw/master/big_buck_bunny.mp4\n     (+) Video --vid=1 (*) (h264 640x360 23.962fps)\n     (+) Audio --aid=1 --alang=eng (*) (aac 2ch 22050Hz)\n    AO: [pulse] 22050Hz stereo 2ch float\n    VO: [opengl] 640x360 yuv420p\n    AV: 00:00:38 / 00:01:00 (64%) A-V:  0.000 Cache:  9s+1MB\n    \"\"\"\n    \n    # fetch this terminal session's window title\n    \u003e\u003e\u003e response = requests.post(url, data={'window-title': True})\n    \u003e\u003e\u003e response.text\n    'me@hostname: ~'\n    # this maybe nice depending if the tool you want to muxnect sets a\n    # a custom title to the pane sesion which could be useful to us\n\n    # kill this tmux window\n    \u003e\u003e\u003e requests.post(url, data={'kill':'true'})\n    \u003cResponse [200]\u003e\n\nSyntactic Sugar\n---------------\n\nmuxnect also provides a simple API for Python to make POST requests:\n\n.. code:: python\n\n    \u003e\u003e\u003e import muxnect\n    \u003e\u003e\u003e url = 'http://localhost:6060/muxnect/cute_cli'\n    \u003e\u003e\u003e client = muxnect.Client(url, default_data={'enter':'true'})\n    \u003e\u003e\u003e client.send('type this, press enter and kill session', data={'kill':'true'})\n\nInstallation\n------------\n\nYou must have `tmux \u003chttps://github.com/tmux/tmux\u003e`__ installed to use\nthis. You may have to install it from source, if it ain't in\nyour `apt` repositories.\n\nmuxnect works best with Python 3.\n\nInstall the latest stable release from pypa:\n\n::\n\n    $ pip install muxnect\n\nOr install the latest development version:\n\n::\n\n    $ git clone https://github.com/ritiek/muxnect\n    $ cd muxnect\n    $ python setup.py install\n\nUsage\n-----\n\n::\n\n    usage: muxnect [-h] -c CMD -w WINDOW_NAME [-d] [-s SESSION_NAME]\n                     [-b BIND_ADDRESS] [-p PORT]\n\n    Send input to just about any interactive command-line tool through a local web\n    server\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -d, --detach          detach from ongoing session (default: False)\n      -s SESSION_NAME, --session-name SESSION_NAME\n                            tmux's session name (default: muxnect)\n      -b BIND_ADDRESS, --bind-address BIND_ADDRESS\n                            address to bind on, local network: 0.0.0.0 (default:\n                            127.0.0.1)\n      -p PORT, --port PORT  port number to listen on (default: 6060)\n\n    required arguments:\n      -c CMD, --cmd CMD     interactive command to send input to (default: None)\n      -w WINDOW_NAME, --window-name WINDOW_NAME\n                            tmux's window name (default: None)\n\nThe URL is generated in the form:\n\n::\n\n    http://\u003chostaddress\u003e:\u003cport\u003e/\u003csession_name\u003e/\u003cwindow_name\u003e\n\nThe POST request can take the following parameters:\n\n::\n\n    keys - mouse events/keystrokes to send (Default: None)\n    separator - split `keys` parameter on a character or string (Default: None)\n    enter - send enter key immediately after sending `keys` (Default: False)\n    window-title - get current window title for the terminal session (Default: False)\n    capture-pane - capture text visible in the current pane (Default: False)\n    kill - kill tmux window after proceeding with any other params (Default: False)\n\nExtending Further\n-----------------\n\nThere are some other interesting things you could do, such as the ability to control videos running on your laptop\nwhich is placed meters away from you - with an android app such as `HTTP-Shortcuts \u003chttps://github.com/Waboodoo/HTTP-Shortcuts\u003e`_ (built by `@Waboodoo \u003chttps://github.com/Waboodoo\u003e`_) which can be used to create custom HTTP requests.\n\nLicense\n-------\n\n|License|\n\n.. |Pypi Version| image:: https://img.shields.io/pypi/v/muxnect.svg\n   :target: https://pypi.org/project/muxnect/\n.. |Build Status| image:: https://travis-ci.org/ritiek/muxnect.svg?branch=master\n   :target: https://travis-ci.org/ritiek/muxnect\n.. |License| image:: https://img.shields.io/github/license/ritiek/muxnect.svg\n   :target: https://github.com/ritiek/muxnect/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritiek%2Fmuxnect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fritiek%2Fmuxnect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritiek%2Fmuxnect/lists"}