[Python] 방화벽 로그 DB삽입
너무 대충 짠 코드 import pymysql import ipaddress from datetime import datetime import time import re conn = pymysql.connect(host='localhost', user='userID', password='1234', db='DB', charset='utf8') curs = conn.cursor() sql = "insert into firewall(date, fwrule, src_ip, src_mac, src_port, dst_ip, dst_port)\ values (%s, %s, %s, %s, %s, %s ,%s)" logfile_path = '로그파일경로' logfile_fullpath = logfile_path + '..
2020. 12. 8.
파이썬 mysql 로그 삽입
pymysql 을 이용한 mysql db로그 삽입하기. import pymysql conn = pymysql.connect(host='localhost', user='hello_mysql', password='1', db='logs', charset='utf8') curs = conn.cursor() sql = "insert into access_log(ip, access_time, method, uri, status)\ values (%s,%s, %s, %s,%s)" logfile_path = '/경로/' logfile_fullpath = logfile_path + '파일이름' count = 0 with open(logfile_fullpath, 'r') as f: for line in f: count ..
2020. 8. 25.