The NetCommander CLI provides a command-line interface to control Synaccess netCommander PDUs.
# Install from local directory with CLI dependencies
uv pip install -e ".[cli]"The CLI can be configured using environment variables or command-line options.
NETCOMMANDER_HOST=192.168.1.100
NETCOMMANDER_USER=admin
NETCOMMANDER_PASSWORD=your_password--host TEXT Device IP address
-u, --username TEXT Username (default: admin)
-p, --password TEXT PasswordDisplay the current state of all outlets:
# Table format (default)
python -m netcommander_cli.cli status
# JSON format
python -m netcommander_cli.cli status --output json
# YAML format
python -m netcommander_cli.cli status --output yamlExample Output (table):
NetCommander Status
╭────────┬───────╮
│ Outlet │ State │
├────────┼───────┤
│ 1 │ ON │
│ 2 │ OFF │
│ 3 │ OFF │
│ 4 │ OFF │
│ 5 │ OFF │
╰────────┴───────╯
Total Current: 0.15A
Temperature: XX
# Turn outlet ON
python -m netcommander_cli.cli outlet 1 on
# Turn outlet OFF
python -m netcommander_cli.cli outlet 5 off
# Toggle outlet
python -m netcommander_cli.cli outlet 3 toggle# Turn all outlets ON
python -m netcommander_cli.cli all on
# Turn all outlets OFF
python -m netcommander_cli.cli all offWatch outlet states update in real-time:
# Default 2-second interval
python -m netcommander_cli.cli monitor
# Custom interval (5 seconds)
python -m netcommander_cli.cli monitor --interval 5Press Ctrl+C to stop monitoring.
Display current configuration:
python -m netcommander_cli.cli info# Set up .env file
cat > .env <<EOF
NETCOMMANDER_HOST=192.168.1.100
NETCOMMANDER_USER=admin
NETCOMMANDER_PASSWORD=secret
EOF
# Commands will use .env automatically
python -m netcommander_cli.cli status
python -m netcommander_cli.cli outlet 1 on# Explicit parameters
python -m netcommander_cli.cli --host 192.168.1.100 --password secret status
# Turn on outlet 2
python -m netcommander_cli.cli --host 192.168.1.100 --password secret outlet 2 on#!/bin/bash
# Restart equipment on outlet 1
HOST="192.168.1.100"
PASS="secret"
echo "Turning off outlet 1..."
python -m netcommander_cli.cli --host $HOST --password $PASS outlet 1 off
echo "Waiting 10 seconds..."
sleep 10
echo "Turning on outlet 1..."
python -m netcommander_cli.cli --host $HOST --password $PASS outlet 1 on
echo "Done!"# Get JSON output
python -m netcommander_cli.cli --host 192.168.1.100 status --output json
# Parse with jq
python -m netcommander_cli.cli status --output json | jq '.outlets["1"]'
# Check if outlet 1 is on
if python -m netcommander_cli.cli status --output json | jq -e '.outlets["1"] == true' > /dev/null; then
echo "Outlet 1 is ON"
else
echo "Outlet 1 is OFF"
fiThe CLI provides clear error messages:
# Authentication error
Error: Authentication failed for admin@192.168.1.100
# Connection error
Error: Cannot connect to device: 192.168.1.100
# Invalid outlet number
Error: Invalid outlet number: 6 (must be 1-5)Exit codes:
0- Success1- Error occurred
- Use environment variables for repeated commands
- JSON output is best for scripting and automation
- Monitor mode is useful for real-time troubleshooting
- Save credentials in
.envfile (add to.gitignore!)
# Test connectivity
ping 192.168.1.100
# Try explicit host
python -m netcommander_cli.cli --host 192.168.1.100 status# Check credentials
python -m netcommander_cli.cli info
# Try default password
python -m netcommander_cli.cli --password admin status# Reinstall with CLI dependencies
uv pip install -e ".[cli]"
# Verify installation
python -c "import netcommander_cli; print('OK')"For API documentation, see API_SPECIFICATION.md