Skip to content

Instantly share code, notes, and snippets.

@voice1
Last active November 23, 2021 18:19
Show Gist options
  • Save voice1/f19c2c36005610118fead05d87746cc6 to your computer and use it in GitHub Desktop.
Save voice1/f19c2c36005610118fead05d87746cc6 to your computer and use it in GitHub Desktop.
Switchvox clear all blocked IP's
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Clear blocked IP addresses in switchvox.
Requires pyswitchvox
Feel free to adjust logger if desired.
"""
from pyswitchvox.client import Client
try:
from loguru import logger
except ImportError:
import logging
logger = logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
username = 'admin'
password = 'admin'
address = 'pbx.address.com'
switchvox = Client(address=address, username=username, password=password)
blocked_ips = switchvox.blockedIps.getList()['result']
for blocked_ip in blocked_ips['blocked_ips'].get('blocked_ip', []):
params = {
'blocked_ip_id': blocked_ip['id']
}
logger.info("Unblocking: [{id}] {ip} {limit_type}".format(**blocked_ip))
r = switchvox.blockedIps.remove(**params)
logger.debug(f"{r.method} {r.status_code} {r.reason} - {r.url} ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment