Access Cisco Firewall through Telnet using Python

In my company we have a couple of VPN’s configured and one of the VPN’s is essential to the core business of the company.

That particular VPN from time to time freezes and i need to disconnect it, but that isn’t always a simple task as when i am in vacations i don’t have access to internet so i needed a way for users to be able to disconnect the VPN themselves. The solution was a python script that connects to the Cisco equipment through telnet using the telnetlib.

This is the script:

import telnetlib

pwd1 = “password
pwd2 = “enable_password
cmdVpn = “vpn-sessiondb logoff ipaddress”
cmdEn = “enable”
host = “”

tn = telnetlib.Telnet(host)

tn.write(pwd1 + “\n”)
tn.write(cmdEn + “\n”)
tn.write(pwd2 + “\n”)
tn.write(cmdVpn + “\n”)
print tn.read_all()
print “Operation completed”

One thought on “Access Cisco Firewall through Telnet using Python

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s