Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cisco2911/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GCCIS-IST-LabAutomation
Ensure python2.4 is installed and pip is installed then run either<br>
python -m pip install -r requirements.txt<br>
or<br>
pip install -r requirements.txt<br>

to reset a 2911 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py<br>
then run<br>
python reset.py<br>
and power cycle the 2911<br>
1 change: 1 addition & 0 deletions Cisco2911/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyserial
97 changes: 97 additions & 0 deletions Cisco2911/reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# writen for python 2.7

# should reset a ciscos password and configuration if plugged into a 2911
# router when it is rebooting
# EDIT THE TWO port= LINES IF YOUR COM PORT IS DIFFERENT
import serial
import subprocess
import shlex

#baudrate = get_baudrate('COM1') # linux

console = serial.Serial(
port='COM1', #windows
#port='/dev/ttyUSB0', #what I expect it to be on Linux, dmesg when you plug in to find out
baudrate=9600, #default baudrate
parity='N', #default parity
stopbits=1, #default stopbits
bytesize=8, #default bytesize
timeout=8
)

print(console.isOpen())

#wait until break will do something
startup_text = ''
while 'program load complete,' not in startup_text:
startup_text += console.read(console.inWaiting())

#send break command
while 'rommon' not in startup_text:
console.send_break()
startup_text += console.read(console.inWaiting())
print(startup_text)

#make sure we enter rommon and set config register
if 'rommon' in startup_text:
print("entered rommon")
console.write('confreg 0x2142\r\n')
print("confreg 0x2142")
console.write('reset\r\n')
print("reset")

#TODO Should be able to change this to a one line so that port does not need to be reused
print("closing connection in case default baudrate was not used")
console.close()
console = serial.Serial(
port='COM1', #windows
#port='/dev/ttyUSB0', #what I expect it to be on Linux, dmesg when you plug in to find out
baudrate=9600, #default baudrate
parity='N', #default parity
stopbits=1, #default stopbits
bytesize=8, #default bytesize
timeout=8
)
print("console opened")
print(console.isOpen())

print("entering boot read loop")
#watch for the initialization prompt
startup_text = ''
while '[yes/no]:' not in startup_text:
startup_text += console.read(console.inWaiting())

print("Removing the current configuration")
#reset the device
console.write('no\r\n')

print("waiting for Router>")
startup_text = ''
while 'Router>' not in startup_text:
console.write('\r\n')
startup_text += console.read(console.inWaiting())
print(startup_text)

console.write('enable\r\n')
console.write('delete nvram:/startup-config\r\n')
console.write('\r\n')
console.write('\r\n')
console.write('write erase\r\n')
console.write('\r\n')
console.write('\r\n')
print(console.read(console.inWaiting()))
console.write('configure terminal\r\n')
console.write('config-register 0x2102\r\n')
console.write('exit\r\n')
console.write('reload\r\n')
console.write('no\r\n')
print("completed")
#console.write('...\r\n') #\r\n is windows syntax? need to write a break

def get_baudrate(device):
command = 'stty < {0}'.format(device)
proc_retval = subprocess.check_output(shlex.split(command))
baudrate = int(proc_retval.split()[1])
return baudrate
10 changes: 10 additions & 0 deletions Cisco3550/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GCCIS-IST-LabAutomation
Ensure python2.4 is installed and pip is installed then run either<br>
python -m pip install -r requirements.txt<br>
or<br>
pip install -r requirements.txt<br>

to reset a 3550 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 3550 and the COM is correct in reset.py<br>
then run<br>
python reset.py<br>
and power cycle the 3550 and hold the mode button<br>
1 change: 1 addition & 0 deletions Cisco3550/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyserial
83 changes: 83 additions & 0 deletions Cisco3550/reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# writen for python 2.7

# should reset a ciscos password and configuration if plugged into a 2911
# router when it is rebooting
# EDIT THE TWO port= LINES IF YOUR COM PORT IS DIFFERENT
import serial
import subprocess
import shlex

#baudrate = get_baudrate('COM1') # linux

console = serial.Serial(
port='COM1', #windows
#port='/dev/ttyUSB0', #what I expect it to be on Linux, dmesg when you plug in to find out
baudrate=9600, #default baudrate
parity='N', #default parity
stopbits=1, #default stopbits
bytesize=8, #default bytesize
timeout=8
)

print(console.isOpen())

#wait until break will do something
startup_text = ''
while 'program load complete,' not in startup_text:
startup_text += console.read(console.inWaiting())

#send break command
while 'switch' not in startup_text:
console.send_break()
startup_text += console.read(console.inWaiting())
print(startup_text)

#make sure we enter rommon and set config register
if 'switch' in startup_text:
print("entered rommon")
console.write('flash_init\r\n')
print("flash_init")
console.write('load_helper\r\n')
print('load_helper')
console.write('rename flash:config.txt flash:config.old\r\n')
print('renamed config')
console.write('boot')
print("booting")

print("entering boot read loop")
#watch for the initialization prompt
startup_text = ''
while '[yes/no]:' not in startup_text:
startup_text += console.read(console.inWaiting())

print("Removing the current configuration")
#reset the device
console.write('no\r\n')

print("waiting for Router>")
startup_text = ''
while 'Router>' not in startup_text:
console.write('\r\n')
startup_text += console.read(console.inWaiting())
print(startup_text)

console.write('enable\r\n')
console.write('delete flash:config.old\r\n')
console.write('\r\n')
console.write('\r\n')
console.write('write erase\r\n')
console.write('\r\n')
console.write('\r\n')
print(console.read(console.inWaiting()))
console.write('reload\r\n')
console.write('no\r\n')
print("completed")
#console.write('...\r\n') #\r\n is windows syntax? need to write a break

def get_baudrate(device):
command = 'stty < {0}'.format(device)
proc_retval = subprocess.check_output(shlex.split(command))
baudrate = int(proc_retval.split()[1])
return baudrate