ํŒŒ์ด์ฌ netmiko ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋„คํŠธ์›Œํฌ ์žฅ๋น„ ์ ‘์†
Network

ํŒŒ์ด์ฌ netmiko ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋„คํŠธ์›Œํฌ ์žฅ๋น„ ์ ‘์†

1. netmiko

๋„คํŠธ์›Œํฌ ์žฅ๋น„์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

์ง€์› ๊ฐ€๋Šฅํ•œ ๋„คํŠธ์›Œํฌ ์žฅ๋น„ OS๊ฐ€ ๋ณ„๋„๋กœ ์žˆ์Œ

๋”๋ณด๊ธฐ

netmiko/PLATFORMS.md

Supported Platforms

Regularly tested

  • Arista vEOS
  • Cisco ASA
  • Cisco IOS
  • Cisco IOS-XE
  • Cisco IOS-XR
  • Cisco NX-OS
  • Cisco SG300
  • HP ProCurve
  • Juniper Junos
  • Linux

Limited testing

  • 6Wind
  • Adtran OS
  • Alcatel AOS6/AOS8
  • Apresia Systems AEOS
  • Broadcom ICOS
  • Calix B6
  • Centec Networks
  • Cisco AireOS (Wireless LAN Controllers)
  • CloudGenix ION
  • Dell OS9 (Force10)
  • Dell OS10
  • Dell PowerConnect
  • Ericsson IPOS
  • Extreme ERS (Avaya)
  • Extreme VSP (Avaya)
  • Extreme VDX (Brocade)
  • Extreme MLX/NetIron (Brocade/Foundry)
  • HPE Comware7
  • Huawei
  • Huawei OLT
  • Huawei SmartAX
  • IP Infusion OcNOS
  • Juniper ScreenOS
  • Mellanox
  • MikroTik RouterOS
  • MikroTik SwitchOS
  • NetApp cDOT
  • Netgear ProSafe
  • Nokia/Alcatel SR OS
  • OneAccess
  • Palo Alto PAN-OS
  • Pluribus
  • Ruckus ICX/FastIron
  • Ruijie Networks
  • Supermicro SMIS
  • TPLink JetStream
  • Ubiquiti EdgeSwitch
  • Vyatta VyOS
  • Yamaha
  • ZTE ZXROS

Experimental

  • A10
  • Accedian
  • Allied Telesis AlliedWare Plus
  • Aruba
  • Brocade Fabric OS
  • C-DOT CROS
  • Ciena SAOS
  • Citrix Netscaler
  • Cisco Telepresence
  • Cisco Viptela
  • Check Point GAiA
  • Coriant
  • Dell OS6
  • Dell EMC Isilon
  • Eltex
  • Enterasys
  • Endace
  • Extreme EXOS
  • Extreme Wing
  • Extreme SLX (Brocade)
  • F5 TMSH
  • F5 Linux
  • Fortinet
  • MRV Communications OptiSwitch
  • MRV LX
  • Nokia/Alcatel SR-OS
  • QuantaMesh
  • Rad ETX
  • Raisecom ROAP
  • Sophos SFOS
  • Ubiquiti Unifi Switch
  • Versa Networks FlexVNF
  • Watchguard Firebox
  • 6WIND TurboRouter

์•„๋ž˜ ์‚ฌ์ดํŠธ๋“ค์„ ํ†ตํ•˜์—ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๋‹ค์–‘ํ•œ ์ •๋ณด๋“ค์„ ์ฐธ๊ณ ํ•  ์ˆ˜ ์žˆ์Œ!

netmiko โ–ถ๏ธ https://ktbyers.github.io/netmiko/docs/netmiko/index.html

 

netmiko API documentation

The SSHDetect class tries to automatically guess the device type running on the SSH remote end. Be careful that the kwargs 'device_type' must be set to 'autodetect', otherwise it won't work at all. Parameters *args : list The same *args that you might pr

ktbyers.github.io

netmiko github โ–ถ๏ธ https://github.com/ktbyers/netmiko

 

GitHub - ktbyers/netmiko: Multi-vendor library to simplify Paramiko SSH connections to network devices

Multi-vendor library to simplify Paramiko SSH connections to network devices - GitHub - ktbyers/netmiko: Multi-vendor library to simplify Paramiko SSH connections to network devices

github.com

 

2. netmiko ์„ค์น˜

โ–ถ๏ธ pip3 install netmiko

 

3. ์žฅ๋น„ ์ ‘์†

device type ํ™•์ธ ํ›„ ์ ‘์†์„ ์œ„ํ•œ ์ •๋ณด(IP, Account ์ •๋ณด, Port ๋“ฑ) ์ž…๋ ฅ

๋”๋ณด๊ธฐ

'device_type' currently supported platforms are: 

  • a10
  • accedian
  • adtran_os
  • alcatel_aos
  • alcatel_sros
  • allied_telesis_awplus
  • apresia_aeos
  • arista_eos
  • aruba_os
  • aruba_osswitch
  • aruba_procurve
  • avaya_ers
  • avaya_vsp
  • broadcom_icos
  • brocade_fastiron
  • brocade_fos
  • brocade_netiron
  • brocade_nos
  • brocade_vdx
  • brocade_vyos
  • calix_b6
  • cdot_cros
  • centec_os
  • checkpoint_gaia
  • ciena_saos
  • cisco_asa
  • cisco_ftd
  • cisco_ios
  • cisco_nxos
  • cisco_s300
  • cisco_tp
  • cisco_wlc
  • cisco_xe
  • cisco_xr
  • cloudgenix_ion
  • coriant
  • dell_dnos9
  • dell_force10
  • dell_isilon
  • dell_os10
  • dell_os6
  • dell_os9
  • dell_powerconnect
  • dlink_ds
  • eltex
  • eltex_esr
  • endace
  • enterasys
  • ericsson_ipos
  • extreme
  • extreme_ers
  • extreme_exos
  • extreme_netiron
  • extreme_nos
  • extreme_slx
  • extreme_vdx
  • extreme_vsp
  • extreme_wing
  • f5_linux
  • f5_ltm
  • f5_tmsh
  • flexvnf
  • fortinet
  • generic
  • generic_termserver
  • hp_comware
  • hp_procurve
  • huawei
  • huawei_olt
  • huawei_smartax
  • huawei_vrpv8
  • ipinfusion_ocnos
  • juniper
  • juniper_junos
  • juniper_screenos
  • keymile
  • keymile_nos
  • linux
  • mellanox
  • mellanox_mlnxos
  • mikrotik_routeros
  • mikrotik_switchos
  • mrv_lx
  • mrv_optiswitch
  • netapp_cdot
  • netgear_prosafe
  • netscaler
  • nokia_sros
  • oneaccess_oneos
  • ovs_linux
  • paloalto_panos
  • pluribus
  • quanta_mesh
  • rad_etx
  • raisecom_roap
  • ruckus_fastiron
  • ruijie_os
  • sixwind_os
  • sophos_sfos
  • supermicro_smis
  • tplink_jetstream
  • ubiquiti_edge
  • ubiquiti_edgerouter
  • ubiquiti_edgeswitch
  • ubiquiti_unifiswitch
  • vyatta_vyos
  • vyos
  • watchguard_fireware
  • yamaha
  • zte_zxros
from netmiko import ConnectHandler

inform = {
    'device_type': '์žฅ๋น„ TYPE',
    'ip': '์žฅ๋น„ IP',
    'username': '์ ‘์† ID',
    'password': '์ ‘์† Password',
    'secret': 'Enable Password',
    'port': 'SSH Port(22๋ฉด ์ƒ๋žต)',
}

net_connect = ConnectHandler(**inform) #dict ํ˜•ํƒœ์ด๊ธฐ ๋•Œ๋ฌธ์— ** ๋ถ™์—ฌ์ฃผ์„ธ์š”

 

4. Enable ๋ชจ๋“œ ์ ‘์†

Enable ๋ชจ๋“œ๊ฐ€ ํ•„์š”ํ•œ ์ปค๋งจ๋“œ์ผ ๊ฒฝ์šฐ Eanble ๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝ

net_connect.enable() #์ ‘์†
net_connect.exit_enable_mode() #์ข…๋ฃŒ

net_connect.check_enable_mode #Enable ๋ชจ๋“œ๋ฉด True, ์•„๋‹ˆ๋ฉด False

 

5. Config ๋ชจ๋“œ ์ ‘์†

Config ๋ชจ๋“œ๊ฐ€ ํ•„์š”ํ•œ ์ปค๋งจ๋“œ์ผ ๊ฒฝ์šฐ Config ๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝ

net_connect.config_mode() #์ ‘์†
net_connect.exit_config_mode() #์ข…๋ฃŒ

net_connect.check_config_mode #Config ๋ชจ๋“œ๋ฉด True, ์•„๋‹ˆ๋ฉด False

 

5. ์ปค๋งจ๋“œ  ์ „์†ก

send_command('์ปค๋งจ๋“œ')

- ํ•œ๊ฐœ์˜ ์ปค๋งจ๋“œ ์ „์†ก

 

send_config_set('์ปค๋งจ๋“œ')

- Config ๋ชจ๋“œ์—์„œ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ปค๋งจ๋“œ ์ „์†ก

 

send_config_from_file('ํŒŒ์ผ ์ด๋ฆ„')

- Config ๋ชจ๋“œ์—์„œ ํŒŒ์ผ ์ „์†ก

net_connect.send_command('์ปค๋งจ๋“œ')
net_connect.send_config_set('์ปค๋งจ๋“œ')
net_connect.send_config_from_file('ํŒŒ์ผ ์ด๋ฆ„')

 

6. ๊ทธ ์™ธ

find_prompt()

-ํ˜„์žฌ ํ”„๋กฌํ”„ํŠธ ๋ฐ˜ํ™˜

 

commit()

- commit(commit์ด ํ•„์š”ํ•œ OS๋งŒ ์‚ฌ์šฉ)

 

disconnect()

- ssh ์ข…๋ฃŒ

net_connect.find_prompt()
net_connect.commit()
net_connect.disconnect()

 

7. ํ™œ์šฉ

๋ชฉ์ 

- 1๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ Interface Input Statistics ์ค‘ ์ •์ƒ์ ์ด์ง€ ์•Š์€ ํŒจํ‚ท ๋ชจ๋‹ˆํ„ฐ๋ง

 

ํŒŒ์ด์ฌ ์ฝ”๋“œ

- netmiko : ๋„คํŠธ์›Œํฌ ์žฅ๋น„ ์ ‘์†ํ•˜์—ฌ ์ปค๋งจ๋“œ ์ „์†ก

- matplotlib : ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

- pandas : ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ

- ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์ž๊ฐ€ ์•„๋‹ˆ๋ผ,,, ํšจ์œจ์ ์ธ ์ข‹์€ ์ฝ”๋“œ๊ฐ€ ์•„๋‹ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค ๐Ÿค”

- ์ผ๋‹จ์€ ๊ฒฐ๊ณผ ํ™•์ธ์„ ์œ„ํ•˜์—ฌ 1๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ 5๋ถ„์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค

from netmiko import ConnectHandler
from datetime import datetime
import matplotlib.pyplot as plt
import pandas as pd
import time

inform = {
    'device_type': '์ƒ๋žต',
    'ip': '์ƒ๋žต',
    'username': '์ƒ๋žต',
    'password': '์ƒ๋žต',
    'secret': '์ƒ๋žต',
    'port': '์ƒ๋žต',
}
start_now = datetime.now()
input_df = pd.DataFrame({'runts': 0,
                         'giants': 0,
                         'throttles': 0,
                         'CRC': 0,
                         'overrun': 0,
                         'discarded': 0},
                         index=[start_now],
                         columns=['runts', 'giants', 'throttles', 'CRC', 'overrun', 'discarded'])
input_dict = {}

#SSH ์ ‘์†
net_connect = ConnectHandler(**inform)

for i in range(1,6):
    
    #์ปค๋งจ๋“œ ์ „์†ก
    interface_output = net_connect.send_command('show interfaces port-channel 90')

    #๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ(pandas ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ)
    interface_output = interface_output.splitlines()

    temp = interface_output[18:20]
    temp_1 = temp[0][5:].replace(",", "")
    temp_2 = temp[1][5:].replace(",", "")
    temp = temp_1 + " " + temp_2
    temp = temp.split(" ")
    input_dict = {temp[j + 1]: int(temp[j]) for j in range(0, len(temp), 2)}

    #์ „์ฒ˜๋ฆฌ๋œ ๋ฐ์ดํ„ฐ ์ž…๋ ฅ(ํ˜„์žฌ ์‹œ๊ฐ„)
    now = datetime.now()
    input_df.loc[now] = [input_dict['runts'], input_dict['giants'], input_dict['throttles'], input_dict['CRC'], input_dict['overrun'], input_dict['discarded']]

    #1๋ถ„ ๊ฐ„๊ฒฉ
    time.sleep(60)

#๋ฐ์ดํ„ฐ ์ถœ๋ ฅ
print(input_df)

#๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”(matplotlib ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ)
input_df.plot()
plt.title("INPUT Interface")
plt.xlabel("date")
plt.ylabel("packet numbers")
plt.xlim(start_now, now)
plt.ylim(0, 5)
plt.show()

#SSH ์ข…๋ฃŒ
net_connect.disconnect()

 

show interface ์ปค๋งจ๋“œ ๊ฒฐ๊ณผ(์ฐธ๊ณ ์šฉ)

Hostname# show interfaces port-channel 90
Port-channel 90 is up, line protocol is up
Description: ## ์ƒ๋žต ##
Hardware address is ์ƒ๋žต, Current address is ์ƒ๋žต
Interface index is 1258337280
Minimum number of links to bring Port-channel up is 1
Internet address is not set
Mode of IPv4 Address Assignment : NONE
DHCP Client-ID :4cd98fe7008a
MTU 9216 bytes, IP MTU 9198 bytes
LineSpeed 80000 Mbit
Members in this channel:  Fo 1/53(U) Fo 1/54(U)
ARP type: ARPA, ARP Timeout 04:00:00
Queueing strategy: fifo
Input Statistics:
     94018423348 packets, 49109219847541 bytes
     14519700479 64-byte pkts, 35400750260 over 64-byte pkts, 7641522857 over 127-byte pkts
     4760648399 over 255-byte pkts, 4503678737 over 511-byte pkts, 27192122616 over 1023-byte pkts
     634507634 Multicasts, 386427039 Broadcasts, 92997488675 Unicasts
     0 runts, 0 giants, 0 throttles #18๋ฒˆ ๋ผ์ธ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ
     0 CRC, 0 overrun, 0 discarded #19๋ฒˆ ๋ผ์ธ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ
Output Statistics:
     6062097275 packets, 5141949517949 bytes, 0 underruns
     235353000 64-byte pkts, 1543441098 over 64-byte pkts, 262688975 over 127-byte pkts
     416740508 over 255-byte pkts, 642126887 over 511-byte pkts, 2961746807 over 1023-byte pkts
     1315188671 Multicasts, 447752699 Broadcasts, 4299155905 Unicasts
     0 throttles, 0 discarded, 0 collisions, 0 wreddrops
Rate info (interval 299 seconds):
     Input 91.00 Mbits/sec,      14632 packets/sec, 0.12% of line-rate
     Output 08.00 Mbits/sec,        848 packets/sec, 0.01% of line-rate
Time since last interface status change: 57w4d10h

 

๊ฒฐ๊ณผ๋ฌผ

                            runts  giants  throttles  CRC  overrun  discarded
2021-07-23 15:38:40.733063      0       0          0    0        0          0
2021-07-23 15:38:50.547603      0       0          0    0        0          0
2021-07-23 15:39:51.487370      0       0          0    0        0          0
2021-07-23 15:40:52.432861      0       0          0    0        0          0
2021-07-23 15:41:53.380364      0       0          0    0        0          0
2021-07-23 15:42:54.219639      0       0          0    0        0          0

#runts : ์ˆ˜์‹ ํ•œ ํŒจํ‚ท์˜ ํฌ๊ธฐ๊ฐ€ 64Byte ๋ณด๋‹ค ์ž‘์•„ drop๋œ ํŒจํ‚ท ์ˆ˜
#giants : ์ˆ˜์‹ ํ•œ ํŒจํ‚ท์˜ ํฌ๊ธฐ๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค์— ์„ค์ •๋œ MTU Size ๋ณด๋‹ค ์ปค drop๋œ ํŒจํ‚ท ์ˆ˜
#throttles : ์ˆ˜์‹ ํ•œ ํŒจํ‚ท ๋‚ด์— PAUSE Frame์ด ํฌํ•จ๋œ ํŒจํ‚ท ์ˆ˜(ํŒจํ‚ท ์ „์†ก๋Ÿ‰ ๊ฐ์†Œ)
#CRC : ์ˆ˜์‹ ํ•œ ํŒจํ‚ท์—์„œ CRC/FCS check ๊ฒฐ๊ณผ Error๋กœ drop๋œ ํŒจํ‚ท ์ˆ˜
#overrun : ํŒจํ‚ท์„ ์ˆ˜์‹ ํ•œ ์ธํ„ฐํŽ˜์ด์Šค ๋‚ด์˜ Buffer์—์„œ FIFO ์ •์ฑ…์— ์˜ํ•ด drop๋œ ํŒจํ‚ท ์ˆ˜
#discarded : ์ˆ˜์‹ ํ•œ ํŒจํ‚ท ์ค‘ drop๋œ ํŒจํ‚ท ํ•ฉ

๋‹ค ๊ฐ’์ด 0์ด๋ผ์„œ ๊ทธ๋ž˜ํ”„์— ๋ณด์ด์ง€ ์•Š๋Š”,,, ํ•˜์ง€๋งŒ 0์ธ๊ฒŒ ๋‹คํ–‰์ธ?!

'Network' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

TCP Sequence Number์™€ ACK Number  (1) 2021.07.29
MTU์™€ TCP MSS, UDP  (0) 2021.07.25
๋„คํŠธ์›Œํฌ ์žฅ๋น„ ๊ตฌ์„ฑ ์š”์†Œ  (0) 2021.07.16
L4/L7 Load Balancing  (0) 2021.07.06
IPsec VPN  (0) 2021.06.27