-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit from Ch1 - Ch6, added Python foo for .gitignore
- Loading branch information
Showing
96 changed files
with
132,151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This is a comment | ||
print("hello world") | ||
|
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def subtract(a, b): | ||
c = a - b | ||
return c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/python3 | ||
|
||
import pexpect | ||
|
||
devices = {'iosv-1': {'prompt': 'iosv-1#', 'ip': '172.16.1.20'}, | ||
'iosv-2': {'prompt': 'iosv-2#', 'ip': '172.16.1.21'}} | ||
username = 'cisco' | ||
password = 'cisco' | ||
|
||
for device in devices.keys(): | ||
device_prompt = devices[device]['prompt'] | ||
child = pexpect.spawn('telnet ' + devices[device]['ip']) | ||
child.expect('Username:') | ||
child.sendline(username) | ||
child.expect('Password:') | ||
child.sendline(password) | ||
child.expect(device_prompt) | ||
child.sendline('show version | i V') | ||
child.expect(device_prompt) | ||
print(child.before) | ||
child.sendline('exit') | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/python3 | ||
|
||
import getpass | ||
from pexpect import pxssh | ||
|
||
devices = {'iosv-1': {'prompt': 'iosv-1#', 'ip': '172.16.1.20'}, | ||
'iosv-2': {'prompt': 'iosv-2#', 'ip': '172.16.1.21'}} | ||
commands = ['term length 0', 'show version', 'show run'] | ||
|
||
username = input('Username: ') | ||
password = getpass.getpass('Password: ') | ||
|
||
# Starts the loop for devices | ||
for device in devices.keys(): | ||
outputFileName = device + '_output.txt' | ||
device_prompt = devices[device]['prompt'] | ||
child = pxssh.pxssh() | ||
child.login(devices[device]['ip'], username.strip(), password.strip(), auto_prompt_reset=False) | ||
# Starts the loop for commands and write to output | ||
with open(outputFileName, 'wb') as f: | ||
for command in commands: | ||
child.sendline(command) | ||
child.expect(device_prompt) | ||
f.write(child.before) | ||
|
||
child.logout() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/python3 | ||
|
||
import paramiko, getpass, time | ||
|
||
devices = {'iosv-1': {'ip': '172.16.1.20'}, | ||
'iosv-2': {'ip': '172.16.1.21'}} | ||
commands = ['show version\n', 'show run\n'] | ||
|
||
username = input('Username: ') | ||
password = getpass.getpass('Password: ') | ||
|
||
max_buffer = 65535 | ||
|
||
def clear_buffer(connection): | ||
if connection.recv_ready(): | ||
return connection.recv(max_buffer) | ||
|
||
# Starts the loop for devices | ||
for device in devices.keys(): | ||
outputFileName = device + '_output.txt' | ||
connection = paramiko.SSHClient() | ||
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
connection.connect(devices[device]['ip'], username=username, password=password, look_for_keys=False, allow_agent=False) | ||
new_connection = connection.invoke_shell() | ||
output = clear_buffer(new_connection) | ||
time.sleep(2) | ||
new_connection.send("terminal length 0\n") | ||
output = clear_buffer(new_connection) | ||
with open(outputFileName, 'wb') as f: | ||
for command in commands: | ||
new_connection.send(command) | ||
time.sleep(2) | ||
output = new_connection.recv(max_buffer) | ||
print(output) | ||
f.write(output) | ||
|
||
new_connection.close() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/python3 | ||
|
||
import paramiko, getpass, time, json | ||
|
||
with open('devices.json', 'r') as f: | ||
devices = json.load(f) | ||
|
||
with open('commands.txt', 'r') as f: | ||
commands = [line for line in f.readlines()] | ||
|
||
username = input('Username: ') | ||
password = getpass.getpass('Password: ') | ||
|
||
max_buffer = 65535 | ||
|
||
def clear_buffer(connection): | ||
if connection.recv_ready(): | ||
return connection.recv(max_buffer) | ||
|
||
# Starts the loop for devices | ||
for device in devices.keys(): | ||
outputFileName = device + '_output.txt' | ||
connection = paramiko.SSHClient() | ||
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
connection.connect(devices[device]['ip'], username=username, password=password, look_for_keys=False, allow_agent=False) | ||
new_connection = connection.invoke_shell() | ||
output = clear_buffer(new_connection) | ||
time.sleep(2) | ||
new_connection.send("terminal length 0\n") | ||
output = clear_buffer(new_connection) | ||
with open(outputFileName, 'wb') as f: | ||
for command in commands: | ||
new_connection.send(command) | ||
time.sleep(2) | ||
output = new_connection.recv(max_buffer) | ||
print(output) | ||
f.write(output) | ||
|
||
new_connection.close() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
config t | ||
logging buffered 30000 | ||
end | ||
copy run start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"iosv-1": {"ip": "172.16.1.20"}, | ||
"iosv-2": {"ip": "172.16.1.21"} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"iosv-1": {"ip": "172.16.1.20"}, | ||
"iosv-2": {"ip": "172.16.1.21"} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
terminal length 0 | ||
iosv-1#config t | ||
Enter configuration commands, one per line. End with CNTL/Z. | ||
iosv-1(config)#logging buffered 30000 | ||
iosv-1(config)#end | ||
iosv-1#copy run start | ||
Destination filename [startup-config]? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
terminal length 0 | ||
iosv-2#config t | ||
Enter configuration commands, one per line. End with CNTL/Z. | ||
iosv-2(config)#logging buffered 30000 | ||
iosv-2(config)#end | ||
iosv-2#copy run start | ||
Destination filename [startup-config]? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/python2 | ||
|
||
from __future__ import print_function | ||
from jsonrpclib import Server | ||
import ssl | ||
|
||
ssl._create_default_https_context = ssl._create_unverified_context | ||
|
||
switch = Server("https://admin:arista@192.168.199.158/command-api") | ||
|
||
response = switch.runCmds( 1, [ "show version" ] ) | ||
print('Serial Number: ' + response[0]['serialNumber']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/python2 | ||
|
||
from __future__ import print_function | ||
from jsonrpclib import Server | ||
import ssl, pprint | ||
|
||
ssl._create_default_https_context = ssl._create_unverified_context | ||
|
||
# Run Arista commands thru eAPI | ||
def runAristaCommands(switch_object, list_of_commands): | ||
response = switch_object.runCmds(1, list_of_commands) | ||
return response | ||
|
||
|
||
switch = Server("https://admin:arista@192.168.199.158/command-api") | ||
|
||
commands = ["enable", "configure", "interface ethernet 1/3", "switchport access vlan 100", "end", "write memory"] | ||
|
||
response = runAristaCommands(switch, commands) | ||
pprint.pprint(response) | ||
|
||
|
Oops, something went wrong.