1. netmiko
๋คํธ์ํฌ ์ฅ๋น์ ์ ์ํ๊ธฐ ์ํ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์ง์ ๊ฐ๋ฅํ ๋คํธ์ํฌ ์ฅ๋น OS๊ฐ ๋ณ๋๋ก ์์
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 github โถ๏ธ https://github.com/ktbyers/netmiko
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๋ ํจํท ํฉ
'Network' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
TCP Sequence Number์ ACK Number (2) | 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 |