본문 바로가기

파이썬 코드

(12)
API 수집 예시(시스코 넥서스) import requestsimport jsonfrom datetime import datetimeimport osimport pandas as pdimport time # 환경 변수에서 URL, 사용자 이름, 패스워드를 가져옵니다.url1 = os.getenv('API_URL1', 'https://IP/ins')url2 = os.getenv('API_URL2', 'https://IP/ins')user1 = os.getenv('API_USER', 'ID')password1 = os.getenv('API_PASSWORD', 'PASSWORD')myheaders = {'Content-Type': 'application/json-rpc'} # API 호출을 위한 페이로드 설정payload1 = [    {  ..
파이썬 자동화 -7- import paramiko, time, socks, re, os from getpass import getpass import pandas as pd import openpyxl from tqdm import tqdm from concurrent.futures import as_completed from openpyxl.utils.dataframe import dataframe_to_rows from concurrent.futures import ThreadPoolExecutor, as_completed import threading def juniper_parse_fixed(df, up_t): df.loc[0, "uptime"] = up_t[0] return df def parse_fix(df1): ..
파이썬 자동화 -6- import paramiko, time, socks, re, os from getpass import getpass import pandas as pd import openpyxl from openpyxl.utils.dataframe import dataframe_to_rows from concurrent.futures import ThreadPoolExecutor, as_completed import threading def juniper_parse_fixed(df, up_t): df.loc[0, "uptime"] = up_t[0] return df def re_ver(data): ex2200_match = re.search(r"ex2200", data) if ex2200_match: match2 = ..
network automation -5- import paramiko, time from getpass import getpass import re import openpyxl from openpyxl.utils.dataframe import dataframe_to_rows import pandas as pd def juniper_parse_fixed(df): fpc_rows = df[df["item"].astype(str).str.startswith("FPC")].reset_index(drop=True) ps_rows = df[df["item"].astype(str).str.startswith("Power Supply")].reset_index(drop=True) paired_rows = [] ps_idx = 0 for _, fpc_rows ..
Network Automation -4- import time import paramiko, time import socks from getpass import getpass import re import pandas as pd import os import openpyxl from openpyxl.utils.dataframe import dataframe_to_rows from concurrent.futures import ThreadPoolExecutor, as_completed import threading def juniper_parse(ip_a, u_id, u_pas, lock): try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy(..
networkautomation -3- import time import paramiko, time from getpass import getpass import re import pandas as pd import os import openpyxl from openpyxl.utils.dataframe import dataframe_to_rows def juniper_parse(ip_a, u_id, u_pas): try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip_a, username=u_id, password=u_pas) print("Connected Complete") #interactive shell 선..
텍스트 파일에서 주니퍼 장비 정보 파싱하기 import re import pandas as pd host = re.compile(r"Hostname: (\w{1,30})") model = re.compile(r"Model: (\w{1,7}-\w{1,7})") ver = re.compile(r"Junos: (\w{1,2}.\w{1,3})") serial = re.compile(r"FPC \d{1} \w{1,3} \d{1,2} \w{1,3}-\w{1,6} (\w{1,13})") with open("juniper_rawdata.txt") as f: f_line = f.read().splitlines() h=host.findall(str(f_line)) m=model.findall(str(f_line)) s=serial.findall(str(f_line..
Network automation -2- import time import paramiko, time import socks from getpass import getpass def juniper_parse(ip_a, u_id, u_pas,find_words): try: #socks config sock=socks.socksocket() sock.set_proxy( proxy_type=socks.SOCKS5, addr="Socks Server IP", port=Socks Server Port, username="Socks Server ID", password="Socks Server Password") #sock ssh connect sock.connect((ip_a,22)) ssh = paramiko.SSHClient() ssh.set_mis..