# pysshpass: A Multiplatform SSH Automation Utility
### Overview
`pysshpass` is a Python-based SSH client designed to offer a multiplatform alternative to `sshpass`. It aims to address two key challenges:
1. **Windows Compatibility**: Native `sshpass` options are limited on Windows. `pysshpass` serves as a versatile replacement.
2. **Specialized Devices Support**: Network devices like Palo Alto Firewalls, CloudGenix SD-WAN routers, and F5 load balancers often have unique command-line interfaces and large outputs, which are not fully supported by libraries like Netmiko.
3. **Vendor and OS Agnostic**: Whether you're managing Cisco, Aruba, Palo Alto, or other network devices, `pysshpass` allows seamless automation and parsing, making it ideal for mixed-vendor environments.
### Key Features
- **Comma-Delimited Commands**: Execute multiple commands in sequence using comma-separated values.
- **Prompt Controls**: The script supports custom prompts and prompt counts, offering precise control over when to exit the shell.
- **Timeout Management**: A timeout feature ensures that the utility doesn't hang while waiting for device responses.
- **Quiet Mode**: A `quiet` flag suppresses printed output when running as a library, but retains output in CLI mode.
- **Cross-Platform**: Works across Linux, macOS, and Windows.
### Example CLI Usage
```bash
pysshpass -h "172.16.1.101" -u "cisco" -p "cisco" -c "term len 0,show users,show run" --invoke-shell --prompt "#" --prompt-count 4 -t 15
```
This command runs multiple commands in sequence on an SSH device (IOS), waits for four prompts, and applies a 15-second timeout.
### Use Cases
- Automating tasks on network devices with large configuration outputs.
- Managing multi-modal command-line interfaces.
- Gathering information during network audits.
- Mixed vendor network environment tooling.
- Linux or IoT automation.
---
## CLI Usage
```bash
pysshpass --help
Usage: pysshpass [OPTIONS]
SSH Client for running remote commands.
Options:
-h, --host TEXT SSH Host (ip:port) [required]
-u, --user TEXT SSH Username [required]
-p, --password TEXT SSH Password
-c, --cmds TEXT Commands to run, separated by comma
--invoke-shell/--no-invoke-shell Invoke shell before running the command
[default=True]
--prompt TEXT Prompt to look for before breaking the shell
--prompt-count INTEGER Number of prompts to look for before breaking the shell
-t, --timeout INTEGER Command timeout duration in seconds [default=360]
--disable-auto-add-policy Disable automatically adding the host key [default=False]
--look-for-keys Look for local SSH key [default=False]
-d, --delay FLOAT Delay between sending commands in seconds [default=0.5]
--quiet Suppress output when running as a library
--help Show this message and exit.
```
### Flags Explanation
- `--host`: SSH target (IP or hostname).
- `--user`: SSH username.
- `--password`: SSH password (can be skipped if `PYSSH_PASS` environment variable is set).
- `--cmds`: Comma-separated commands to run.
- `--invoke-shell`: Create an interactive SSH session (default is `True`).
- `--prompt`: Specify the shell prompt to look for.
- `--prompt-count`: How many times the prompt should be matched before breaking the shell.
- `--timeout`: Duration in seconds before the command times out.
- `--disable-auto-add-policy`: Disable the auto-add of SSH keys.
- `--look-for-keys`: Enable local key lookup for SSH authentication.
- `--delay`: Time delay between sending commands.
- `--quiet`: Suppress output when running as a library.
---
### Environment Variable Support for Passwords
For added convenience and security, `pysshpass` allows you to provide the SSH password through an environment variable, avoiding the need to pass it directly via the command line.
- Set the environment variable `PYSSH_PASS` to the desired password:
```bash
export PYSSH_PASS="yourpassword"
```
- If the `--password` option is omitted, `pysshpass` will automatically check for the `PYSSH_PASS` environment variable. This feature is especially useful when running automation scripts where you want to avoid exposing sensitive credentials in the command history.
### Example:
```bash
export PYSSH_PASS="cisco"
pysshpass -h "172.16.101.100" -u "cisco" -c "show version,show inventory" --invoke-shell --prompt "#" --prompt-count 3 -t 10
```
If a password is provided both in the environment variable and the command-line option, the command-line value will take precedence.
---
## More Usage Examples
### 1. Cisco Router
```bash
pysshpass -h "192.168.1.1" -u "admin" -p "password" -c "terminal length 0,show version" --invoke-shell --prompt "#" --prompt-count 3 -t 10
```
### 2. Aruba Switch
```bash
pysshpass -h "192.168.1.2" -u "admin" -p "password" -c "no paging,show interfaces brief" --invoke-shell --prompt ">" --prompt-count 2 -t 10
```
### 3. Palo Alto Firewall
```bash
pysshpass -h "192.168.1.3" -u "admin" -p "password" -c "set cli pager off,show system info,," --invoke-shell --prompt ">" --prompt-count 2 -t 10
```
---
### Library Usage
In addition to being used as a CLI tool, `pysshpass` can also be used as a library:
```python
from PySSHPass.pysshpass import SSHClientWrapper
def automate_device():
ssh_client = SSHClientWrapper(
host="192.168.1.1",
user="admin",
password="password",
cmds="show version",
invoke_shell=True,
prompt="#",
prompt_count=1,
timeout=10,
quiet=True # Suppress output
)
ssh_client.connect()
output = ssh_client.run_commands()
ssh_client.close()
return output
```
### Quiet Mode
The `--quiet` flag suppresses printed output, making it useful for script-based automation where log files are preferred over console output.
---
## Appendix A: Example Using TTP with `pysshpass`
This appendix provides a detailed example of how to use the `pysshpass` library with a TTP (Template Text Parser) helper to parse structured output from network devices. This example demonstrates how to run incremental SSH commands, gather output, and parse it using TTP templates for structured data extraction.
### Overview
In this example, the `SSHClientWrapper` class is used to:
1. Connect to a Cisco router.
2. Execute the `show version` command and parse the version information using a TTP template.
3. Execute the `show inventory` command and parse the inventory details.
The `TTPParserHelper` class is a utility that loads TTP templates and parses raw SSH output into structured data.
### Script Example
```python
from time import sleep
from PySSHPass.pysshpass import SSHClientWrapper
from PySSHPass.helpers.ttp_helper import TTPParserHelper
def test_ssh_client_with_ttp():
# Replace with appropriate SSH credentials and commands
ssh_client = SSHClientWrapper(
host="172.16.101.100",
user="cisco",
password="cisco",
invoke_shell=True,
prompt="#",
prompt_count=3,
timeout=5,
delay=0.5,
quiet=True # Suppress console output in quiet mode
)
# Step 1: Connect to the device
ssh_client.connect()
# Step 2: Run 'show version' command and capture output
ssh_client.cmds = "term len 0,show version"
version_output = ssh_client.run_commands()
# Step 3: Parse the 'show version' output using TTP
version_template_file = './templates/show_version.ttp' # Path to the TTP template for show version
version_parser = TTPParserHelper(ttp_template_file=version_template_file)
parsed_version = version_parser.parse(version_output)
print("Parsed Version Output:\n", parsed_version)
# Step 4: Run 'show inventory' command and capture output
ssh_client.prompt_count = 1
ssh_client.cmds = "show inventory"
inventory_output = ssh_client.run_commands()
# Step 5: Parse the 'show inventory' output using TTP
inventory_template_file = './templates/show_inventory.ttp' # Path to the TTP template for show inventory
inventory_parser = TTPParserHelper(ttp_template_file=inventory_template_file)
parsed_inventory = inventory_parser.parse(inventory_output)
print("Parsed Inventory Output:\n", parsed_inventory)
# Step 6: Close the
connection
ssh_client.close()
if __name__ == "__main__":
test_ssh_client_with_ttp()
```
### Key Components
1. **SSHClientWrapper**:
- Manages the SSH connection and command execution.
- `invoke_shell=True` enables interactive sessions, necessary for running multiple commands like `show version` and `show inventory`.
- The `quiet=True` flag suppresses verbose output during library usage.
2. **TTPParserHelper**:
- Parses SSH output using predefined TTP templates.
- In this example, the `show_version.ttp` and `show_inventory.ttp` templates are used to extract structured data from the device output.
---
### TTP Templates
To parse the output, we need two TTP templates: one for the `show version` command and one for the `show inventory` command. Below are examples of these templates:
#### 1. TTP Template for `show version`
**File: `show_version.ttp`**
```ttp
Version: {{ version }}
```
This template extracts the version information from the output of the `show version` command.
#### 2. TTP Template for `show inventory`
**File: `show_inventory.ttp`**
```ttp
NAME: "{{ inventory_name }}", DESCR: "{{ description }}"
PID: {{ product_id }}, VID: {{ version_id }}, SN: {{ serial_number }}
```
This template extracts details from the `show inventory` command, such as the product ID, version ID, and serial number.
---
### New Feature: Dynamic Prompt Detection (`find_prompt`)
In the latest update, `pysshpass` includes a powerful `find_prompt` feature, which dynamically detects the shell prompt if not explicitly provided by the user. This is particularly useful when connecting to devices with unknown or varying prompt characters, such as network equipment with custom prompts.
#### Key Features of `find_prompt`:
- **Automatic Detection**: If no prompt is specified, `pysshpass` will attempt to detect common prompt characters like `#`, `>`, or `$`.
- **Custom Prompt Matching**: You can customize the characters or strings to look for when identifying the prompt, allowing flexibility for unique prompt configurations.
- **Seamless Integration**: The `find_prompt` method is automatically called if the `--prompt` option is left blank, making it easy to integrate into your existing automation workflows.
#### Example Usage
If you don’t know the prompt for a device, simply leave the `--prompt` option blank, and `pysshpass` will try to find it for you:
```bash
pysshpass -h "192.168.1.1" -u "admin" -p "password" -c "show version,show interfaces" --invoke-shell --prompt-count 2 -t 15
```
If you want to customize the characters that are detected as a prompt, you can specify them when using `pysshpass` as a library:
```python
ssh_client = SSHClientWrapper(
host="192.168.1.1",
user="admin",
password="password",
invoke_shell=True,
prompt="", # Empty prompt to enable dynamic prompt detection
prompt_count=1,
timeout=10
)
# Connect to the device and dynamically find the prompt (e.g., detecting '#' or '>')
ssh_client.connect()
detected_prompt = ssh_client.find_prompt(ends_with=('#', '>'))
print(f"Detected prompt: {detected_prompt}")
# Continue running commands after detecting the prompt
ssh_client.cmds = "show version"
output = ssh_client.run_commands()
ssh_client.close()
```
In this example, `find_prompt` will look for `#` or `>` at the end of a line to detect the prompt dynamically. You can easily modify the `ends_with` parameter to handle custom prompts (e.g., `ends_with=('$', '%')` for Unix-like systems).
This new feature makes `pysshpass` more adaptable to diverse environments, ensuring that you can automate SSH interactions even when the exact prompt is not known beforehand.
---
## Appendix B: Build Instructions
To build and test `pysshpass` locally, follow the steps below:
### Step 1: Install Build Tools
Before you can build the package, ensure that `setuptools` and `wheel` are installed:
```bash
pip install setuptools wheel
```
### Step 2: Build the Package
To build the wheel file, run the following command:
```bash
python setup.py bdist_wheel
```
This will generate a `.whl` file in the `dist/` directory.
### Step 3: Test the Wheel Locally
To test the built package locally, run:
```bash
pip install dist/pysshpass-0.2.0-py3-none-any.whl
```
### Step 4: Upload the Package to TestPyPI
For testing purposes, you can upload the wheel to TestPyPI:
```bash
pip install twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
```
### Step 5: Upload the Package to PyPI
Once satisfied with testing, upload the package to PyPI:
```bash
twine upload dist/*
```
Make sure to configure your credentials in `~/.pypirc` for automated authentication.
---
## License
PySSHPass is licensed under the **GNU General Public License v3 (GPLv3)**. For more details, see the [LICENSE](LICENSE) file.
Raw data
{
"_id": null,
"home_page": "https://github.com/scottpeterman/pysshpass",
"name": "pysshpass",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Scott Peterman",
"author_email": "scottpeterman@gmail.com",
"download_url": null,
"platform": null,
"description": "# pysshpass: A Multiplatform SSH Automation Utility\r\n\r\n### Overview\r\n\r\n`pysshpass` is a Python-based SSH client designed to offer a multiplatform alternative to `sshpass`. It aims to address two key challenges:\r\n\r\n1. **Windows Compatibility**: Native `sshpass` options are limited on Windows. `pysshpass` serves as a versatile replacement.\r\n2. **Specialized Devices Support**: Network devices like Palo Alto Firewalls, CloudGenix SD-WAN routers, and F5 load balancers often have unique command-line interfaces and large outputs, which are not fully supported by libraries like Netmiko.\r\n3. **Vendor and OS Agnostic**: Whether you're managing Cisco, Aruba, Palo Alto, or other network devices, `pysshpass` allows seamless automation and parsing, making it ideal for mixed-vendor environments.\r\n\r\n### Key Features\r\n\r\n- **Comma-Delimited Commands**: Execute multiple commands in sequence using comma-separated values.\r\n- **Prompt Controls**: The script supports custom prompts and prompt counts, offering precise control over when to exit the shell.\r\n- **Timeout Management**: A timeout feature ensures that the utility doesn't hang while waiting for device responses.\r\n- **Quiet Mode**: A `quiet` flag suppresses printed output when running as a library, but retains output in CLI mode.\r\n- **Cross-Platform**: Works across Linux, macOS, and Windows.\r\n\r\n### Example CLI Usage\r\n\r\n```bash\r\npysshpass -h \"172.16.1.101\" -u \"cisco\" -p \"cisco\" -c \"term len 0,show users,show run\" --invoke-shell --prompt \"#\" --prompt-count 4 -t 15\r\n```\r\n\r\nThis command runs multiple commands in sequence on an SSH device (IOS), waits for four prompts, and applies a 15-second timeout.\r\n\r\n### Use Cases\r\n\r\n- Automating tasks on network devices with large configuration outputs.\r\n- Managing multi-modal command-line interfaces.\r\n- Gathering information during network audits.\r\n- Mixed vendor network environment tooling.\r\n- Linux or IoT automation.\r\n\r\n---\r\n\r\n## CLI Usage\r\n\r\n```bash\r\npysshpass --help\r\nUsage: pysshpass [OPTIONS]\r\n\r\n SSH Client for running remote commands.\r\n\r\nOptions:\r\n -h, --host TEXT SSH Host (ip:port) [required]\r\n -u, --user TEXT SSH Username [required]\r\n -p, --password TEXT SSH Password\r\n -c, --cmds TEXT Commands to run, separated by comma\r\n --invoke-shell/--no-invoke-shell Invoke shell before running the command\r\n [default=True]\r\n --prompt TEXT Prompt to look for before breaking the shell\r\n --prompt-count INTEGER Number of prompts to look for before breaking the shell\r\n -t, --timeout INTEGER Command timeout duration in seconds [default=360]\r\n --disable-auto-add-policy Disable automatically adding the host key [default=False]\r\n --look-for-keys Look for local SSH key [default=False]\r\n -d, --delay FLOAT Delay between sending commands in seconds [default=0.5]\r\n --quiet Suppress output when running as a library\r\n --help Show this message and exit.\r\n```\r\n\r\n### Flags Explanation\r\n\r\n- `--host`: SSH target (IP or hostname).\r\n- `--user`: SSH username.\r\n- `--password`: SSH password (can be skipped if `PYSSH_PASS` environment variable is set).\r\n- `--cmds`: Comma-separated commands to run.\r\n- `--invoke-shell`: Create an interactive SSH session (default is `True`).\r\n- `--prompt`: Specify the shell prompt to look for.\r\n- `--prompt-count`: How many times the prompt should be matched before breaking the shell.\r\n- `--timeout`: Duration in seconds before the command times out.\r\n- `--disable-auto-add-policy`: Disable the auto-add of SSH keys.\r\n- `--look-for-keys`: Enable local key lookup for SSH authentication.\r\n- `--delay`: Time delay between sending commands.\r\n- `--quiet`: Suppress output when running as a library.\r\n\r\n---\r\n\r\n### Environment Variable Support for Passwords\r\n\r\nFor added convenience and security, `pysshpass` allows you to provide the SSH password through an environment variable, avoiding the need to pass it directly via the command line.\r\n\r\n- Set the environment variable `PYSSH_PASS` to the desired password:\r\n\r\n```bash\r\nexport PYSSH_PASS=\"yourpassword\"\r\n```\r\n\r\n- If the `--password` option is omitted, `pysshpass` will automatically check for the `PYSSH_PASS` environment variable. This feature is especially useful when running automation scripts where you want to avoid exposing sensitive credentials in the command history.\r\n\r\n### Example:\r\n\r\n```bash\r\nexport PYSSH_PASS=\"cisco\"\r\npysshpass -h \"172.16.101.100\" -u \"cisco\" -c \"show version,show inventory\" --invoke-shell --prompt \"#\" --prompt-count 3 -t 10\r\n```\r\n\r\nIf a password is provided both in the environment variable and the command-line option, the command-line value will take precedence.\r\n\r\n---\r\n\r\n## More Usage Examples\r\n\r\n### 1. Cisco Router\r\n\r\n```bash\r\npysshpass -h \"192.168.1.1\" -u \"admin\" -p \"password\" -c \"terminal length 0,show version\" --invoke-shell --prompt \"#\" --prompt-count 3 -t 10\r\n```\r\n\r\n### 2. Aruba Switch\r\n\r\n```bash\r\npysshpass -h \"192.168.1.2\" -u \"admin\" -p \"password\" -c \"no paging,show interfaces brief\" --invoke-shell --prompt \">\" --prompt-count 2 -t 10\r\n```\r\n\r\n### 3. Palo Alto Firewall\r\n\r\n```bash\r\npysshpass -h \"192.168.1.3\" -u \"admin\" -p \"password\" -c \"set cli pager off,show system info,,\" --invoke-shell --prompt \">\" --prompt-count 2 -t 10\r\n```\r\n\r\n---\r\n\r\n### Library Usage\r\n\r\nIn addition to being used as a CLI tool, `pysshpass` can also be used as a library:\r\n\r\n```python\r\nfrom PySSHPass.pysshpass import SSHClientWrapper\r\n\r\ndef automate_device():\r\n ssh_client = SSHClientWrapper(\r\n host=\"192.168.1.1\",\r\n user=\"admin\",\r\n password=\"password\",\r\n cmds=\"show version\",\r\n invoke_shell=True,\r\n prompt=\"#\",\r\n prompt_count=1,\r\n timeout=10,\r\n quiet=True # Suppress output\r\n )\r\n \r\n ssh_client.connect()\r\n output = ssh_client.run_commands()\r\n ssh_client.close()\r\n return output\r\n```\r\n\r\n### Quiet Mode\r\n\r\nThe `--quiet` flag suppresses printed output, making it useful for script-based automation where log files are preferred over console output.\r\n\r\n---\r\n\r\n## Appendix A: Example Using TTP with `pysshpass`\r\n\r\nThis appendix provides a detailed example of how to use the `pysshpass` library with a TTP (Template Text Parser) helper to parse structured output from network devices. This example demonstrates how to run incremental SSH commands, gather output, and parse it using TTP templates for structured data extraction.\r\n\r\n### Overview\r\n\r\nIn this example, the `SSHClientWrapper` class is used to:\r\n1. Connect to a Cisco router.\r\n2. Execute the `show version` command and parse the version information using a TTP template.\r\n3. Execute the `show inventory` command and parse the inventory details.\r\n\r\nThe `TTPParserHelper` class is a utility that loads TTP templates and parses raw SSH output into structured data.\r\n\r\n### Script Example\r\n\r\n```python\r\nfrom time import sleep\r\nfrom PySSHPass.pysshpass import SSHClientWrapper\r\nfrom PySSHPass.helpers.ttp_helper import TTPParserHelper\r\n\r\ndef test_ssh_client_with_ttp():\r\n # Replace with appropriate SSH credentials and commands\r\n ssh_client = SSHClientWrapper(\r\n host=\"172.16.101.100\",\r\n user=\"cisco\",\r\n password=\"cisco\",\r\n invoke_shell=True,\r\n prompt=\"#\",\r\n prompt_count=3,\r\n timeout=5,\r\n delay=0.5,\r\n quiet=True # Suppress console output in quiet mode\r\n )\r\n\r\n # Step 1: Connect to the device\r\n ssh_client.connect()\r\n\r\n # Step 2: Run 'show version' command and capture output\r\n ssh_client.cmds = \"term len 0,show version\"\r\n version_output = ssh_client.run_commands()\r\n\r\n # Step 3: Parse the 'show version' output using TTP\r\n version_template_file = './templates/show_version.ttp' # Path to the TTP template for show version\r\n version_parser = TTPParserHelper(ttp_template_file=version_template_file)\r\n parsed_version = version_parser.parse(version_output)\r\n print(\"Parsed Version Output:\\n\", parsed_version)\r\n\r\n # Step 4: Run 'show inventory' command and capture output\r\n ssh_client.prompt_count = 1\r\n ssh_client.cmds = \"show inventory\"\r\n inventory_output = ssh_client.run_commands()\r\n\r\n # Step 5: Parse the 'show inventory' output using TTP\r\n inventory_template_file = './templates/show_inventory.ttp' # Path to the TTP template for show inventory\r\n inventory_parser = TTPParserHelper(ttp_template_file=inventory_template_file)\r\n parsed_inventory = inventory_parser.parse(inventory_output)\r\n print(\"Parsed Inventory Output:\\n\", parsed_inventory)\r\n\r\n # Step 6: Close the\r\n\r\n connection\r\n ssh_client.close()\r\n\r\nif __name__ == \"__main__\":\r\n test_ssh_client_with_ttp()\r\n```\r\n\r\n### Key Components\r\n\r\n1. **SSHClientWrapper**: \r\n - Manages the SSH connection and command execution.\r\n - `invoke_shell=True` enables interactive sessions, necessary for running multiple commands like `show version` and `show inventory`.\r\n - The `quiet=True` flag suppresses verbose output during library usage.\r\n\r\n2. **TTPParserHelper**:\r\n - Parses SSH output using predefined TTP templates.\r\n - In this example, the `show_version.ttp` and `show_inventory.ttp` templates are used to extract structured data from the device output.\r\n\r\n---\r\n\r\n### TTP Templates\r\n\r\nTo parse the output, we need two TTP templates: one for the `show version` command and one for the `show inventory` command. Below are examples of these templates:\r\n\r\n#### 1. TTP Template for `show version`\r\n**File: `show_version.ttp`**\r\n```ttp\r\nVersion: {{ version }}\r\n```\r\n\r\nThis template extracts the version information from the output of the `show version` command.\r\n\r\n#### 2. TTP Template for `show inventory`\r\n**File: `show_inventory.ttp`**\r\n```ttp\r\nNAME: \"{{ inventory_name }}\", DESCR: \"{{ description }}\"\r\nPID: {{ product_id }}, VID: {{ version_id }}, SN: {{ serial_number }}\r\n```\r\n\r\nThis template extracts details from the `show inventory` command, such as the product ID, version ID, and serial number.\r\n\r\n---\r\n\r\n### New Feature: Dynamic Prompt Detection (`find_prompt`)\r\n\r\nIn the latest update, `pysshpass` includes a powerful `find_prompt` feature, which dynamically detects the shell prompt if not explicitly provided by the user. This is particularly useful when connecting to devices with unknown or varying prompt characters, such as network equipment with custom prompts.\r\n\r\n#### Key Features of `find_prompt`:\r\n- **Automatic Detection**: If no prompt is specified, `pysshpass` will attempt to detect common prompt characters like `#`, `>`, or `$`.\r\n- **Custom Prompt Matching**: You can customize the characters or strings to look for when identifying the prompt, allowing flexibility for unique prompt configurations.\r\n- **Seamless Integration**: The `find_prompt` method is automatically called if the `--prompt` option is left blank, making it easy to integrate into your existing automation workflows.\r\n\r\n#### Example Usage\r\n\r\nIf you don\u00e2\u20ac\u2122t know the prompt for a device, simply leave the `--prompt` option blank, and `pysshpass` will try to find it for you:\r\n\r\n```bash\r\npysshpass -h \"192.168.1.1\" -u \"admin\" -p \"password\" -c \"show version,show interfaces\" --invoke-shell --prompt-count 2 -t 15\r\n```\r\n\r\nIf you want to customize the characters that are detected as a prompt, you can specify them when using `pysshpass` as a library:\r\n\r\n```python\r\nssh_client = SSHClientWrapper(\r\n host=\"192.168.1.1\",\r\n user=\"admin\",\r\n password=\"password\",\r\n invoke_shell=True,\r\n prompt=\"\", # Empty prompt to enable dynamic prompt detection\r\n prompt_count=1,\r\n timeout=10\r\n)\r\n\r\n# Connect to the device and dynamically find the prompt (e.g., detecting '#' or '>')\r\nssh_client.connect()\r\ndetected_prompt = ssh_client.find_prompt(ends_with=('#', '>'))\r\nprint(f\"Detected prompt: {detected_prompt}\")\r\n\r\n# Continue running commands after detecting the prompt\r\nssh_client.cmds = \"show version\"\r\noutput = ssh_client.run_commands()\r\nssh_client.close()\r\n```\r\n\r\nIn this example, `find_prompt` will look for `#` or `>` at the end of a line to detect the prompt dynamically. You can easily modify the `ends_with` parameter to handle custom prompts (e.g., `ends_with=('$', '%')` for Unix-like systems).\r\n\r\nThis new feature makes `pysshpass` more adaptable to diverse environments, ensuring that you can automate SSH interactions even when the exact prompt is not known beforehand.\r\n\r\n--- \r\n\r\n## Appendix B: Build Instructions\r\n\r\nTo build and test `pysshpass` locally, follow the steps below:\r\n\r\n### Step 1: Install Build Tools\r\n\r\nBefore you can build the package, ensure that `setuptools` and `wheel` are installed:\r\n\r\n```bash\r\npip install setuptools wheel\r\n```\r\n\r\n### Step 2: Build the Package\r\n\r\nTo build the wheel file, run the following command:\r\n\r\n```bash\r\npython setup.py bdist_wheel\r\n```\r\n\r\nThis will generate a `.whl` file in the `dist/` directory.\r\n\r\n### Step 3: Test the Wheel Locally\r\n\r\nTo test the built package locally, run:\r\n\r\n```bash\r\npip install dist/pysshpass-0.2.0-py3-none-any.whl\r\n```\r\n\r\n### Step 4: Upload the Package to TestPyPI\r\n\r\nFor testing purposes, you can upload the wheel to TestPyPI:\r\n\r\n```bash\r\npip install twine\r\ntwine upload --repository-url https://test.pypi.org/legacy/ dist/*\r\n```\r\n\r\n### Step 5: Upload the Package to PyPI\r\n\r\nOnce satisfied with testing, upload the package to PyPI:\r\n\r\n```bash\r\ntwine upload dist/*\r\n```\r\n\r\nMake sure to configure your credentials in `~/.pypirc` for automated authentication.\r\n\r\n---\r\n\r\n## License\r\n\r\nPySSHPass is licensed under the **GNU General Public License v3 (GPLv3)**. For more details, see the [LICENSE](LICENSE) file.\r\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Python-based, Windows compatible SSH automation client designed to offer a vendor agnostic alternative to Netmiko or `sshpass`.",
"version": "0.2.2",
"project_urls": {
"Homepage": "https://github.com/scottpeterman/pysshpass"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ef856e8311b2c2ad93e6bb204354b4c45b3267ab418efb5826204ff4ca70615b",
"md5": "54a94a960143400ffc06af4c4fd4bffe",
"sha256": "5ef83c43967a7cd78d7f10db6866ae5c7423807f42381397166e1643ff1985c5"
},
"downloads": -1,
"filename": "pysshpass-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "54a94a960143400ffc06af4c4fd4bffe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 22993,
"upload_time": "2024-10-15T15:35:10",
"upload_time_iso_8601": "2024-10-15T15:35:10.292860Z",
"url": "https://files.pythonhosted.org/packages/ef/85/6e8311b2c2ad93e6bb204354b4c45b3267ab418efb5826204ff4ca70615b/pysshpass-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 15:35:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "scottpeterman",
"github_project": "pysshpass",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "bcrypt",
"specs": [
[
">=",
"4.2.0"
]
]
},
{
"name": "cffi",
"specs": [
[
">=",
"1.17.1"
]
]
},
{
"name": "click",
"specs": [
[
">=",
"8.1.7"
]
]
},
{
"name": "colorama",
"specs": [
[
">=",
"0.4.6"
]
]
},
{
"name": "cryptography",
"specs": [
[
">=",
"43.0.1"
]
]
},
{
"name": "paramiko",
"specs": [
[
">=",
"3.5.0"
]
]
},
{
"name": "pycparser",
"specs": [
[
">=",
"2.22"
]
]
},
{
"name": "PyNaCl",
"specs": [
[
">=",
"1.5.0"
]
]
},
{
"name": "ttp",
"specs": [
[
">=",
"0.9.5"
]
]
}
],
"lcname": "pysshpass"
}