当前位置: 首页 > news >正文

太极安全监控系统0.8

完善后的代码及功能详细介绍
完善后的代码
python

import os
import sys
import subprocess
import re
import datetime
import threading
import tkinter as tk
from tkinter import messagebox, simpledialog, ttk
import scapy.all as scapy
import whois
import numpy as np
from sklearn.ensemble import IsolationForest
from sklearn.svm import OneClassSVM
from sklearn.preprocessing import StandardScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
import json
import random
import socket
import pickle
from geopy.geocoders import Nominatim
from collections import defaultdict
import Evtx.Evtx as evtx
import tensorflow as tf
import psutil
import logging
import time
import multiprocessing
from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout, QPushButton, QListWidget, QLabel, QTreeView, QFileSystemModel, QTableWidget, QTableWidgetItem, QComboBox, QProgressBar
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyQt5.QtGui import QPixmap, QImage
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas# 配置日志
logging.basicConfig(filename=os.path.join('logs', 'security_system.log'), level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')# 确保 TensorFlow 使用 GPU
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:try:tf.config.experimental.set_memory_growth(gpus[0], True)except RuntimeError as e:print(e)logging.error(f"TensorFlow GPU configuration error: {e}")# 全局变量
suspicious_activities = []
packets = []
geolocator_cache = {}
whois_cache = {}
taiji_shield = None# 动态获取网络接口名称
def get_network_interfaces():return scapy.get_if_list()# 配置防火墙规则
def configure_firewall():print("配置防火墙规则...")logging.info("配置防火墙规则...")# Windows 防火墙规则配置示例subprocess.run(["netsh", "advfirewall", "set", "currentprofile", "state", "on"])# 阻断已知恶意 IP 地址known_malicious_ips = ["192.168.1.100", "10.0.0.1"]for ip in known_malicious_ips:subprocess.run(["netsh", "advfirewall", "firewall", "add", "rule", "name=BlockMaliciousIP", "dir=in", "action=block", "remoteip=" + ip])subprocess.run(["netsh", "advfirewall", "firewall", "add", "rule", "name=BlockMaliciousIP", "dir=out", "action=block", "remoteip=" + ip])# 读取和解析系统日志
def analyze_logs(log_file):print(f"分析日志文件 {log_file}...")logging.info(f"分析日志文件 {log_file}...")suspicious_activities = []try:with evtx.Evtx(log_file) as log:for record in log.records():xml = record.xml()if "IPTables-Input" in xml or "IPTables-Output" in xml or "Security-Audit" in xml or "Security-Event" in xml:match = re.search(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', xml)if match:ip_address = match.group(1)timestamp = re.search(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}', xml)if timestamp:timestamp = timestamp.group(0)suspicious_activities.append((timestamp, ip_address, xml.strip()))except Exception as e:print(f"分析日志文件时发生错误: {e}")logging.error(f"分析日志文件时发生错误: {e}")return suspicious_activities# 使用 Scapy 抓取特定端口的流量
def capture_traffic(interface, port):print(f"抓取 {interface} 上的 {port} 端口流量...")logging.info(f"抓取 {interface} 上的 {port} 端口流量...")packets = scapy.sniff(iface=interface, filter=f"port {port}", count=100)return packets# 获取入侵者地理位置
def get_geolocation(ip_address, geolocator_cache):if ip_address in geolocator_cache:return geolocator_cache[ip_address]try:geolocator = Nominatim(user_agent="security_system")location = geolocator.geocode(ip_address)if location:geolocator_cache[ip_address] = f"{location.city}, {location.country}"return geolocator_cache[ip_address]else:geolocator_cache[ip_address] = "未知位置"return "未知位置"except Exception as e:geolocator_cache[ip_address] = f"获取地理位置失败: {str(e)}"logging.error(f"获取地理位置失败: {e}")return geolocator_cache[ip_address]# 验证 IP 地址
def verify_ip(ip_address, whois_cache):if ip_address in whois_cache:return whois_cache[ip_address]try:w = whois.whois(ip_address)if w and w.get('nets'):whois_cache[ip_address] 
http://www.lryc.cn/news/469896.html

相关文章:

  • E-清楚姐姐的布告规划【01背包】
  • 哪款宠物空气净化器噪音低?希喂、美的、安德迈测评分享
  • 2024年10月23日第一部分
  • 医院信息化与智能化系统(9)
  • 逻辑回归与神经网络
  • 隨筆 20241024 Kafka 数据格式解析:批次头与数据体
  • 【WiFi7】 支持wifi7的手机
  • LabVIEW偏振调制激光高精度测距系统
  • Python Pandas 数据分析的得力工具:简介
  • Llama 3.2-Vision 多模态大模型本地运行教程
  • iOS 18.2 可让欧盟用户删除App Store、Safari、信息、相机和照片应用
  • 照片怎么转换成pdf?盘点6种图片转pdf格式有效方法,直击要点!
  • 【Qt】Windows下Qt连接DM数据库
  • 2024 你还不会微前端吗 (上) — 从巨石应用到微应用
  • WPF+MVVM案例实战(三)- 动态数字卡片效果实现
  • #网络安全#渗透测试# 渗透测试应用
  • MicroServer Gen8再玩 OCP万兆光口+IT直通之二
  • 【JAVA面试题】Java和C++主要区别有哪些?各有哪些优缺点?
  • 保姆级教程!!教你通过【Pycharm远程】连接服务器运行项目代码
  • JMeter详细介绍和相关概念
  • 如何使用Git
  • Redis 哨兵 问题
  • 安卓基础001
  • shodan2:绕过shodan高级会员限制+metasploit批量验证漏洞
  • 【JAVA毕业设计】基于Vue和SpringBoot的母婴商城系统
  • 探索Python安全字符串处理的奥秘:MarkupSafe库揭秘
  • Xcode真机运行正常,打包报错
  • Android Audio基础——音频混音线程介绍(十)
  • 【Excel】函数各类公式总结
  • 【入门篇】2.9 系统滴答定时器 SysTick