This Python script is designed to perform MAC address lookup in a network infrastructure and optionally tag the corresponding switch ports with a VLAN ID. It utilizes the Netmiko library for SSH connectivity to network devices and supports Cisco-formatted, Linux-formatted, and Windows-formatted MAC addresses.
netmiko
library (pip install netmiko
)PyYAML
library (pip install pyyaml
)To run the script, execute the following command:
python3 Cisco_MAC_Finder&Tagging.py
The script requires a file named MAC_file.txt
in the same directory. This file should contain a list of MAC addresses, with each MAC address on a new line.
The script will output the following information:
The script will prompt you to enter your username and password for authentication. Please provide the appropriate credentials to connect to the network devices.
You have the option to provide a VLAN ID. If you choose to do so, the script will configure the switch ports where the MAC address is found with the specified VLAN ID. If you don't provide a VLAN ID, the script will only perform the MAC address lookup.
Here is an example of how to use the script:
Edit a file named MAC_file.txt
in the same directory and add the MAC addresses to be looked up, each on a new line.
Edit a YAML file named switches.yml
containing the switch information. The format should be as follows:
switch_site: - name: switch_name mgmt_ip: switch_ip port: ssh_port
Replace switch_site
with a meaningful name for your switch site, switch_name
with the switch's hostname, switch_ip
with the management IP address, and ssh_port
with the SSH port number.
Run the script using the command:
python3 Cisco_MAC_Finder&Tagging.py
Enter your username, password, and VLAN ID (if desired) when prompted.
The script will perform the MAC address lookup and display the results on the terminal.
If you provided a VLAN ID, the script will also configure the switch ports where the MAC address is found with the specified VLAN ID.
Note: Make sure to modify the script and YAML file according to your network environment and requirements.
Certainly! Here's the formatted use case that you can insert into your README file on GitHub:
A network administrator wants to streamline the process of locating MAC addresses in the network and assigning them to specific VLANs. They have a list of MAC addresses stored in a file (MAC_file.txt), and they want to automate the process of searching for these MAC addresses across multiple switches and configuring the associated switch ports with a specific VLAN.
The administrator runs the script and is prompted to enter their login credentials (username and password) and the VLAN ID they want to assign to the switch ports. The script then reads the MAC addresses from the file, one by one, and performs the following steps for each MAC address:
By using this script, the network administrator can save time and effort by automating the process of MAC address lookup and VLAN configuration, making network management more efficient and less error-prone.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please create an issue or submit a pull request.
This project is licensed under the MIT License.
Owner
Contributors
Categories
Programming Languages
PythonLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community