A ssh echo server which provides an interactive shell
Project description
py-ssh-echo
A simple AsyncSSH-based echo SSH server designed for testing purposes. This server provides an interactive shell and will echo any input sent over SSH, and logs basic session information (e.g., username, IP, bytes received, session duration) to stdout.
Features
- Echoes input: Whatever you send to the server is echoed back, line by linepy.
- Tracks session metadata: Collects details like username, IP address, bytes received, and session duration.
- Easy to use: Can be run as a standalone server or imported as a module in other Python projects.
- Customizable: Choose the port for the server, and track session details through a callback function.
Installation
You can install this package from PyPI:
pip install ssh-echo-server
Alternatively, you can install it from the source:
git clone https://github.com/yourusername/ssh-echo-server.git
cd ssh-echo-server
pip install .
Usage
As a standalone server
Run the server from the command line:
python -m ssh_echo_server.server
By default, the server will run on localhost:2222. You can specify a custom port by passing it as an argument:
python -m ssh_echo_server.server 2022
As an imported module
You can also import and run the server from your Python scripts:
from ssh_echo_server import start_echo_server
async def main():
# Optionally, define a callback to track session data
def track_session(info):
print(f"Session ended: {info}")
# Start the echo server on a custom port
server = await start_echo_server(port=2022, session_tracker=track_session)
try:
await asyncio.sleep(60) # Keep the server running for 60 seconds
finally:
# Gracefully shut down the server
server.close()
await server.wait_closed()
import asyncio
asyncio.run(main())
Running Tests
This package includes unit tests that ensure the server functions correctly.
Install the test dependencies:
pip install -r requirements.txt
Run the tests with pytest:
pytest
Run the tests with logs:
'''bash pytest -s '''
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
- Create a new branch.
- Make your changes.
- Create a pull request.
Author
Chris Morgan
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_ssh_echo-0.0.1.tar.gz.
File metadata
- Download URL: py_ssh_echo-0.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e32969ffc1ef9fce185647a9774539f1932855e501fbecbd2ce301a8ac331fb7
|
|
| MD5 |
3568bf2aa81f53a7de8686970ad18fda
|
|
| BLAKE2b-256 |
db7a317d92974846fd09c52e8264d49511e383eadd38e4cfad825e228aaf6394
|
File details
Details for the file py_ssh_echo-0.0.1-py3-none-any.whl.
File metadata
- Download URL: py_ssh_echo-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1593c4067d23c0a88aabbc24e1fb316bf6aa973d64b60c8220895c4bdb43f13b
|
|
| MD5 |
cbbb7f9c759132b3ad0ac82ab491f470
|
|
| BLAKE2b-256 |
382b1e597b5edbad50c4b3e76da096cc72b1b3123df8c07ed570b0b8a68697c2
|