Read failed login attempts from logs and add source IPs to an address list.
api = librouteros.connect(...)
address_list = api.path('ip', 'firewall', 'address-list')
MikroTik API over TLS (port 8729) with curl: mikrotik api examples
#!/bin/bash
HOST="192.168.88.1"
USER="admin"
PASS=""
PORT=8729
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
client := &http.Client{}
url := "https://ROUTER_IP/rest/ip/address"
payload := map[string]string"address":"192.0.2.40/24","interface":"ether1"
b, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(b))
req.SetBasicAuth("admin","yourpass")
req.Header.Set("Content-Type","application/json")
resp, err := client.Do(req)
if err != nil panic(err)
defer resp.Body.Close()
fmt.Println("Status:", resp.Status)
}
For binary API in Go, use packages like github.com/go-routeros/routeros. Read failed login attempts from logs and add
api = librouteros.connect(
host='192.168.88.1',
username='admin',
password='your_password',
port=8728
) For binary API in Go, use packages like github
connection.path('ip', 'firewall', 'nat').add(
chain='srcnat',
src_address='10.0.0.0/24',
action='masquerade'
)
voucher = generate_voucher()
create_voucher_user(voucher, minutes_valid=120)
export_data = api('/export/print', 'compact': '')
config_text = '\n'.join([line[''] for line in export_data])