cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1447
Views
0
Helpful
2
Replies

User tracking script

yasseryy
Level 1
Level 1

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  

1 Accepted Solution

Accepted Solutions

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()

View solution in original post

2 Replies 2

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()

sgd729
Level 1
Level 1

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

Review Cisco Networking products for a $25 gift card