A command-line tool for executing Mikrotik RouterOS commands via API or SSH.
go build -o mt .For SSH mode, sshpass is required:
brew install hudochenkov/sshpass/sshpass # macOS
apt install sshpass # Debian/UbuntuCopy .env.example to .env and configure:
MT_HOST=192.168.88.1
MT_USER=admin
MT_PASSWORD=yourpassword
MT_PORT=8728
#MT_USE_TLS=true
#MT_USE_SSH=trueEnable API on your Mikrotik: /ip service enable api
Uses RouterOS API protocol (port 8728, or 8729 with TLS):
./mt -c '/system/resource/print'
./mt -c '/interface/print'
./mt -c '/ip/service/print ?name=api'
./mt -c '/ip/service/set =.id=*0 =address=10.0.0.0/24'Uses SSH for CLI commands (port 22). Supports export and other CLI-only commands:
./mt -ssh -c '/user export'
./mt -ssh -c '/system resource print'
./mt -ssh -c '/interface print where type=ether'- API mode: Use
?prefix (e.g.,?name=api) - SSH mode: Use
wherekeyword (e.g.,where type=ether)
When copying the binary to another folder, macOS may block it due to security restrictions. Two solutions:
Option 1: Symlink (recommended)
ln -sf /path/to/mt /destination/mtOption 2: Re-sign after copying
cp mt /destination/
codesign -s - /destination/mt