forked from DSaimon/pyneng-online-may-aug-2019
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
546 changed files
with
13,844 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Node rules: | ||
## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
## Dependency directory | ||
## Commenting this out is preferred by some people, see | ||
## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
|
||
# Book build output | ||
_book | ||
|
||
# eBook build output | ||
*.epub | ||
*.mobi | ||
pyneng.pdf | ||
|
||
# OS generated files # | ||
# ###################### | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
ehthumbs.db | ||
Thumbs.db | ||
|
||
# Vim undo files. Python# | ||
# ####################### | ||
*.un~ | ||
*.pyc | ||
*.swp |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# pyneng-online-may-aug-2019 | ||
## pyneng-online-may-aug-2019 | ||
|
||
|
||
Материалы курса "Python для сетевых инженеров" (pyneng-online-7) |
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,8 @@ | ||
|
||
access_template = ['switchport mode access', | ||
'switchport access vlan {}', | ||
'switchport nonegotiate', | ||
'spanning-tree portfast', | ||
'spanning-tree bpduguard enable'] | ||
|
||
print('\n'.join(access_template).format(5)) |
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,15 @@ | ||
from sys import argv | ||
|
||
interface = argv[1] | ||
vlan = argv[2] | ||
# второй вариант: | ||
# interface, vlan = argv[1:3] | ||
|
||
access_template = ['switchport mode access', | ||
'switchport access vlan {}', | ||
'switchport nonegotiate', | ||
'spanning-tree portfast', | ||
'spanning-tree bpduguard enable'] | ||
|
||
print('interface {}'.format(interface)) | ||
print('\n'.join(access_template).format(vlan)) |
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,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
access_template = ['switchport mode access', | ||
'switchport access vlan {}', | ||
'switchport nonegotiate', | ||
'spanning-tree portfast', | ||
'spanning-tree bpduguard enable'] | ||
|
||
print('\n'.join(access_template).format(5)) |
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,13 @@ | ||
|
||
interface = input('Enter interface type and number: ') | ||
vlan = input('Enter VLAN number: ') | ||
|
||
access_template = ['switchport mode access', | ||
'switchport access vlan {}', | ||
'switchport nonegotiate', | ||
'spanning-tree portfast', | ||
'spanning-tree bpduguard enable'] | ||
|
||
print('\n' + '-' * 30) | ||
print('interface {}'.format(interface)) | ||
print('\n'.join(access_template).format(vlan)) |
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,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
username = input('Введите имя пользователя: ') | ||
password = input('Введите пароль: ') | ||
|
||
if len(password) < 8: | ||
print('Пароль слишком короткий') | ||
elif username in password: | ||
print('Пароль содержит имя пользователя') | ||
else: | ||
print('Пароль для пользователя {} установлен'.format(username)) | ||
|
||
''' | ||
Usage example: | ||
$ python check_password.py | ||
Введите имя пользователя: nata | ||
Введите пароль: nata1234 | ||
Пароль содержит имя пользователя | ||
$ python check_password.py | ||
Введите имя пользователя: nata | ||
Введите пароль: 123nata123 | ||
Пароль содержит имя пользователя | ||
$ python check_password.py | ||
Введите имя пользователя: nata | ||
Введите пароль: 1234 | ||
Пароль слишком короткий | ||
$ python check_password.py | ||
Введите имя пользователя: nata | ||
Введите пароль: 123456789 | ||
Пароль для пользователя nata установлен | ||
''' |
31 changes: 31 additions & 0 deletions
31
examples/06_control_structures/check_password_with_while.py
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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
username = input('Введите имя пользователя: ') | ||
password = input('Введите пароль: ') | ||
|
||
password_correct = False | ||
|
||
while not password_correct: | ||
if len(password) < 8: | ||
print('Пароль слишком короткий\n') | ||
password = input('Введите пароль еще раз: ') | ||
elif username in password: | ||
print('Пароль содержит имя пользователя\n') | ||
password = input('Введите пароль еще раз: ') | ||
else: | ||
print('Пароль для пользователя {} установлен'.format(username)) | ||
password_correct = True | ||
|
||
''' | ||
Example: | ||
$ python check_password_with_while.py | ||
Введите имя пользователя: nata | ||
Введите пароль: nata | ||
Пароль слишком короткий | ||
Введите пароль еще раз: natanata | ||
Пароль содержит имя пользователя | ||
Введите пароль еще раз: 123345345345 | ||
Пароль для пользователя nata установлен | ||
''' |
13 changes: 13 additions & 0 deletions
13
examples/06_control_structures/check_password_with_while_break.py
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,13 @@ | ||
username = input('Введите имя пользователя: ') | ||
password = input('Введите пароль: ') | ||
|
||
while True: | ||
if len(password) < 8: | ||
print('Пароль слишком короткий\n') | ||
elif username in password: | ||
print('Пароль содержит имя пользователя\n') | ||
else: | ||
print('Пароль для пользователя {} установлен'.format(username)) | ||
# завершает цикл while | ||
break | ||
password = input('Введите пароль еще раз: ') |
15 changes: 15 additions & 0 deletions
15
examples/06_control_structures/check_password_with_while_continue.py
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,15 @@ | ||
username = input('Введите имя пользователя: ') | ||
password = input('Введите пароль: ') | ||
|
||
password_correct = False | ||
|
||
while not password_correct: | ||
if len(password) < 8: | ||
print('Пароль слишком короткий\n') | ||
elif username in password: | ||
print('Пароль содержит имя пользователя\n') | ||
else: | ||
print('Пароль для пользователя {} установлен'.format(username)) | ||
password_correct = True | ||
continue | ||
password = input('Введите пароль еще раз: ') |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
try: | ||
a = input('Введите первое число: ') | ||
b = input('Введите второе число: ') | ||
print('Результат: ', int(a) / int(b)) | ||
except ValueError: | ||
print('Пожалуйста, вводите только числа') | ||
except ZeroDivisionError: | ||
print('На ноль делить нельзя') | ||
''' | ||
Example: | ||
$ python divide.py | ||
Введите первое число: 3 | ||
Введите второе число: 1 | ||
Результат: 3 | ||
$ python divide.py | ||
Введите первое число: 5 | ||
Введите второе число: 0 | ||
Результат: На ноль делить нельзя | ||
$ python divide.py | ||
Введите первое число: qewr | ||
Введите второе число: 3 | ||
Результат: Пожалуйста, вводите только числа | ||
''' |
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
try: | ||
a = input('Введите первое число: ') | ||
b = input('Введите второе число: ') | ||
print('Результат: ', int(a) / int(b)) | ||
except (ValueError, ZeroDivisionError): | ||
print('Что-то пошло не так...') | ||
''' | ||
Example: | ||
$ python divide_ver2.py | ||
Введите первое число: wer | ||
Введите второе число: 4 | ||
Результат: Что-то пошло не так... | ||
$ python divide_ver2.py | ||
Введите первое число: 5 | ||
Введите второе число: 0 | ||
Результат: Что-то пошло не так... | ||
''' |
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,23 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
try: | ||
a = input('Введите первое число: ') | ||
b = input('Введите второе число: ') | ||
result = int(a) / int(b) | ||
except (ValueError, ZeroDivisionError): | ||
print('Что-то пошло не так...') | ||
else: | ||
print('Результат в квадрате: ', result**2) | ||
''' | ||
Example: | ||
$ python divide_ver3.py | ||
Введите первое число: 10 | ||
Введите второе число: 2 | ||
Результат в квадрате: 25 | ||
$ python divide_ver3.py | ||
Введите первое число: werq | ||
Введите второе число: 3 | ||
Что-то пошло не так... | ||
''' |
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,33 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
try: | ||
a = input('Введите первое число: ') | ||
b = input('Введите второе число: ') | ||
result = int(a) / int(b) | ||
except (ValueError, ZeroDivisionError): | ||
print('Что-то пошло не так...') | ||
else: | ||
print('Результат в квадрате: ', result**2) | ||
finally: | ||
print('Вот и сказочке конец, а кто слушал - молодец.') | ||
''' | ||
Example: | ||
$ python divide_ver4.py | ||
Введите первое число: 10 | ||
Введите второе число: 2 | ||
Результат в квадрате: 25 | ||
Вот и сказочке конец, а кто слушал - молодец. | ||
$ python divide_ver4.py | ||
Введите первое число: qwerewr | ||
Введите второе число: 3 | ||
Что-то пошло не так... | ||
Вот и сказочке конец, а кто слушал - молодец. | ||
$ python divide_ver4.py | ||
Введите первое число: 4 | ||
Введите второе число: 0 | ||
Что-то пошло не так... | ||
Вот и сказочке конец, а кто слушал - молодец. | ||
''' |
34 changes: 34 additions & 0 deletions
34
examples/06_control_structures/generate_access_port_config.py
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 @@ | ||
access_template = [ | ||
'switchport mode access', 'switchport access vlan', | ||
'spanning-tree portfast', 'spanning-tree bpduguard enable' | ||
] | ||
|
||
fast_int = {'access': {'0/12': 10, '0/14': 11, '0/16': 17, '0/17': 150}} | ||
|
||
for intf, vlan in fast_int['access'].items(): | ||
print('interface FastEthernet' + intf) | ||
for command in access_template: | ||
if command.endswith('access vlan'): | ||
print(' {} {}'.format(command, vlan)) | ||
else: | ||
print(' {}'.format(command)) | ||
''' | ||
Example: | ||
python generate_access_port_config.py | ||
interface FastEthernet0/12 | ||
switchport mode access | ||
switchport access vlan 10 | ||
spanning-tree portfast | ||
spanning-tree bpduguard enable | ||
interface FastEthernet0/14 | ||
switchport mode access | ||
switchport access vlan 11 | ||
spanning-tree portfast | ||
spanning-tree bpduguard enable | ||
interface FastEthernet0/16 | ||
switchport mode access | ||
switchport access vlan 17 | ||
spanning-tree portfast | ||
spanning-tree bpduguard enable | ||
''' |
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,16 @@ | ||
en | ||
conf t | ||
no int Gi0/0/0.300 | ||
no int Gi0/0/0.301 | ||
no int Gi0/0/0.302 | ||
int range gi0/0/0-2 | ||
channel-group 1 mode active | ||
interface Port-channel1.300 | ||
encapsulation dot1Q 300 | ||
vrf forwarding Management | ||
ip address 10.16.19.35 255.255.255.248 | ||
interface Port-channel1.600 | ||
encapsulation dot1Q 600 | ||
vrf forwarding Management | ||
ip address 10.15.16.35 255.255.255.248 | ||
|
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,26 @@ | ||
# Вариант с try/except | ||
while True: | ||
a = input("Введите число: ") | ||
b = input("Введите второе число: ") | ||
try: | ||
result = int(a) / int(b) | ||
except ValueError: | ||
print("Поддерживаются только числа") | ||
except ZeroDivisionError: | ||
print("На ноль делить нельзя") | ||
else: | ||
print(result) | ||
break | ||
|
||
# Аналогичное решение без try/except | ||
while True: | ||
a = input("Введите число: ") | ||
b = input("Введите второе число: ") | ||
if a.isdigit() and b.isdigit(): | ||
if int(b) == 0: | ||
print("На ноль делить нельзя") | ||
else: | ||
print(int(a) / int(b)) | ||
break | ||
else: | ||
print("Поддерживаются только числа") |
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,10 @@ | ||
! | ||
service timestamps debug datetime msec localtime show-timezone year | ||
service timestamps log datetime msec localtime show-timezone year | ||
service password-encryption | ||
service sequence-numbers | ||
! | ||
no ip domain lookup | ||
! | ||
ip ssh version 2 | ||
! |
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,11 @@ | ||
! | ||
service timestamps debug datetime msec localtime show-timezone year | ||
service timestamps log datetime msec localtime show-timezone year | ||
service password-encryption | ||
service sequence-numbers | ||
! | ||
no ip domain lookup | ||
! | ||
ip ssh version 2 | ||
! | ||
hostname r2 |
Oops, something went wrong.