SWOSConnector
is a Python class designed to interact with MikroTik SwitchOS devices via their REST API. It provides an easy-to-use interface for managing and retrieving data from these switches.
- Connect to MikroTik SwitchOS devices using REST API.
- Retrieve and set various configurations including VLANs, ports, and more.
- Fetch system information, interface statistics, logs, and other data.
- Manage Spanning Tree Protocol (STP), LLDP, DHCP snooping, and more.
You can install the required dependencies using `pip`:
pip install requests
Basic Example
from swos_connector.connector import SWOSConnector
def get_system(url,username,password):
with SWOSConnector(url, username, password) as swos:
system_info = swos.get_system_info()
return system_info
url = 'http://192.168.88.1'
username = 'admin'
password = 'password'
print(get_system(url,username,password))
get_system_info()
: Retrieve basic system information from the SwitchOS device, such as firmware version, model, and uptime.
get_interface_statistics()
: Fetch statistics for all interfaces, including data rates, errors, and packet counts.get_interface_status()
: Obtain the current status of all interfaces, such as link state and speed.get_mikrotik_links(port_number=None, port_name=None, output_only=None)
: Fetches port link information, such as port names, statuses, and configurations.
set_mikrotik_switch_port(port_number, port_name=None, enabled=True, auto_neg=True)
: Configure a specific switch port, including enabling/disabling it, setting the port name, and configuring auto-negotiation.get_port_statistics()
: Retrieve detailed statistics about each port, such as packet counts, error counts, etc.get_port_isolation()
: Retrieve port isolation settings to understand how traffic is segregated between ports.get_poe_status()
: Retrieve the status of Power over Ethernet (PoE) on each port.
get_mikrotik_vlan_config()
: Retrieve the current VLAN configuration of the device.get_mikrotik_vlan(port_number=None, port_name=None, vlan_id=None, output_only=None)
: Retrieve VLAN settings for a specific port.set_mikrotik_vlan(port_number, vlan_mode=None, vlan_receive=None, vlan_id=None)
: Configure VLAN settings on a specific port, including VLAN mode, VLAN receive mode, and VLAN ID.get_vlan_membership()
: Retrieve detailed VLAN membership information for each port.
get_stp_status()
: Get the current status of the Spanning Tree Protocol (STP) on the device.
get_lldp_neighbors()
: Fetch the LLDP neighbors of the switch, providing details on connected devices.
get_dhcp_snooping_info()
: Retrieve information related to DHCP snooping, including trusted ports and snooping statistics.get_dhcp_snooping_status()
: Retrieve information about DHCP snooping, including binding tables and status.
get_port_mirroring()
: Get the current port mirroring configuration, including source and target ports.get_traffic_mirroring_settings()
: Retrieve the configuration for traffic mirroring (port mirroring).
get_ip_filter_rules()
: Obtain the current IP filter rules configured on the device.
get_qos_settings()
: Retrieve Quality of Service (QoS) settings, such as queue configurations and prioritization.
get_multicast_settings()
: Retrieve multicast-related settings, such as IGMP snooping status.
get_system_logs()
: Fetch the system logs from the SwitchOS device, useful for debugging and monitoring.
get_mac_address_table()
: Retrieve the MAC address table, showing the learned MAC addresses and their corresponding ports.
get_mikrotik_hosts()
: Retrieve host information from the SwitchOS device, including IP and MAC addresses.
MikrotikConnectionError:
Raised when there is an issue connecting to the Mikrotik device.
This project is licensed under the GNU GENERAL PUBLIC LICENSE V3. See the LICENSE file for details.
We welcome contributions to enhance the functionality of this SwitchOS_Connector. Please fork the repository and create a pull request with your improvements. or open a issue to add improvements in code
petrunetworking (Network Enginner)
Developed using the REST API connections.
Inspired by the need for robust network automation tools.