09-12-2017 04:27 AM - edited 03-08-2019 11:59 AM
Hello guys,
can you help in getting a user tracking scripts? Simply I need the mac address and IP for all the devices connected to the switch ports. We can get this manually using the show mac and show arp. I am looking for TCL or Python scripts to automate this
Thank
Solved! Go to Solution.
09-12-2017 05:05 AM
Hello,
I wrote this to manage WLC and never tried on Switches but I think it can do the job.
It uses an Python library called Exscript. Maybe you need to perform some ajusts but if everything is ok, you end up with a file which is the Switch IP address and all mac address inside. You can do the same for arp and get IP address.
#!/usr/bin/python import shutil import os from Exscript.util.interact import read_login from Exscript.protocols import SSH2 from Exscript import Account from sshtunnel import SSHTunnelForwarder print "Authenticating..." user = "" passwd = "" SW_IP = "" port = server.local_bind_port account = Account(user,passwd) conn = SSH2() conn.connect(sw,port) conn.login(account) print "Passing the user out.." conn.execute(user) print "Passing the password out..." conn.execute(passwd) time.sleep( 5 )
print "Take the whole output..." conn.execute("terminal length 0") print "Listing all Mac Address currently joined..." conn.execute("show mac address") f = open("Use Switch IP Here", 'w+') f.write(conn.response) f.close() print "All mac address must be on the file now" conn.send("exit") conn.close()
09-12-2017 05:05 AM
Hello,
I wrote this to manage WLC and never tried on Switches but I think it can do the job.
It uses an Python library called Exscript. Maybe you need to perform some ajusts but if everything is ok, you end up with a file which is the Switch IP address and all mac address inside. You can do the same for arp and get IP address.
#!/usr/bin/python import shutil import os from Exscript.util.interact import read_login from Exscript.protocols import SSH2 from Exscript import Account from sshtunnel import SSHTunnelForwarder print "Authenticating..." user = "" passwd = "" SW_IP = "" port = server.local_bind_port account = Account(user,passwd) conn = SSH2() conn.connect(sw,port) conn.login(account) print "Passing the user out.." conn.execute(user) print "Passing the password out..." conn.execute(passwd) time.sleep( 5 )
print "Take the whole output..." conn.execute("terminal length 0") print "Listing all Mac Address currently joined..." conn.execute("show mac address") f = open("Use Switch IP Here", 'w+') f.write(conn.response) f.close() print "All mac address must be on the file now" conn.send("exit") conn.close()
08-14-2022 02:39 AM
Hi there mate.Im new on Networking R & S but i have a bit knowledge of Python scripting and wrote this script for our customer to Tshoot network easily:
from netmiko import ConnectHandler
from getpass import getpass
Ip_dev = input("IP Device : ")
username = input("Username : ")
password = getpass("enter password : ")
secret = getpass("enter secret : ")
Network_Device = {"host": Ip_dev,
"username": username,
"password": password,
"device_type": "cisco_ios",
"secret": secret}
Connect = ConnectHandler(**Network_Device)
Connect.enable()
def command():
while True:
mac = input("Enter your MAC(ffff.dddd.cccc):")
to_exe = "sh mac add add "+mac
res = Connect.send_command(to_exe)
print(res)
print("Do you want Pass Mac section ? Y/N :")
ans = input()
if (ans == "y" or ans == "Y" or ans == "yes" or ans == "Yes" or ans == "YES"):
continue
else:
break
print("===========================")
print("If u saw That Mac on Uplink Please pay ATTENTION on this section")
print("===========================")
print(Connect.send_command("sh cdp nei detail"))
print("===========================")
print("If u saw That Mac on Uplink Please pay ATTENTION on this section")
print("===========================")
command()
while True:
print("Do you want start again? y/n : ")
ans2 = input()
if (ans2 == "y" or ans2 == "Y" or ans2 == "yes" or ans2 == "Yes" or ans2 == "YES"):
command()
else:
break
this is my linked in : https://linkedin.com/in/amirhossein-sajjadian-4252b1178
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide