查看华为防火墙会话和流量top数据
from netmiko.ssh_dispatcher import ConnectHandler
import pymysql
import time
device = {
"device_type": "huawei",
"ip": "ip",
"username": "backup",
"password": "密码",
}
with ConnectHandler(**device) as ssh_conn:
output = ssh_conn.send_command_timing( # command_string可以较好的回显数据
command_string="""
system-view
firewall realtime-statistics enable
diagnose
display firewall online ip traffic top10
display firewall online ip session top10
quit
undo firewall realtime-statistics enable
quit
quit
"""
)
conn = pymysql.connect(host="10.32.236.8",
port=8080,
user="root",
passwd="xxx",
db="firewall",
charset="utf8", )
cursor = conn.cursor(pymysql.cursors.DictCursor)
sql = 'insert into topn(paihang,zhi,time_now) value(%s,%s,%s);'
time_now=time.strftime('%Y-%m-%d %H:%M:%S')
a =0
for s in output.splitlines():
a += 1
if 15 < a < 27 or 34 < a < 46:
try:
num = s.split(' ')
shuzi=num[1] + ':' + num[3]
cursor.execute(sql, (shuzi,num[-1],time_now))
conn.commit()
except Exception as e :
if 16 < a < 27 or 35 < a < 46:
num = s.split(' ')
shuzi=num[1] + ':' + num[3]
cursor.execute(sql, (shuzi, num[-1], time_now))
conn.commit()
—————————————第二版---------------------------------------------------
from netmiko.ssh_dispatcher import ConnectHandler
import pymysql
import time
H3C = {
"device_type": "huawei",
"ip": "ip",
"username": "账号",
"password": "密码",
}
conn = pymysql.connect(host="",
port=8080,
user="root",
passwd="密码",
db="库名",
charset="utf8", )
cursor = conn.cursor(pymysql.cursors.DictCursor)
sql = 'insert into 表名(direction,paihang,time_now) value(%s,%s,%s);'
net_connect = ConnectHandler(**H3C)
net_connect.send_command(command_string='display firewall topn source-ip traffic',expect_string ='')
net_connect.send_command(command_string=r'Y',expect_string = '>',cmd_verify = False)
time.sleep(12)
output = net_connect.send_command(command_string=r'',expect_string = '',cmd_verify = False)
time.sleep(2)
time_now = time.strftime('%Y-%m-%d %H:%M:%S')
cursor.execute(sql, ('source_ip',output,time_now))
time.sleep(1)
# print(output)
net_connect.send_command(command_string='display firewall topn destination-ip traffic',expect_string ='')
time.sleep(14)
outpute = net_connect.send_command(command_string=r'',expect_string = '>',cmd_verify = False)
time.sleep(2)
net_connect.send_command(command_string=r'quit',expect_string = '',cmd_verify = False)
cursor.execute(sql, ('destination_ip',outpute,time_now))
# print(outpute)
conn.commit()
conn.close()
查看华为防火墙会话和流量top数据相关推荐
- 华为防火墙会话 session table
display firewall session table reset firewall session table protocol tcp service http reset firewal ...
- 查看防火墙状态_干货 | 华为防火墙配置,这篇文章强烈推荐收藏学习
1.命令行界面密码:Admin@123 [ ]web-manager enable 开启web 界面管理 2.web界面:默认 admin Admin@123 3.区域 默认区域:trust ...
- 华为防火墙查看日志命令_防火墙接入互联网方式,到底有哪些呢?5分钟学会防火墙入网...
通过静态IP接入互联网 局域网内部所有的PC都不是在10.3.0.0/24网段,均通过DHCP动态获取IP地址.企业从运营商处获取固定的IP地址为1.1.1.1/24.企业需要利用防火墙接入互联网. ...
- ELK+grok+华为防火墙USG6500会话日志
一. 前言 作为一名网络工程师进程要分析网络设备.防火墙设备日志,网上大部分都是通过logstash进行收集syslog日志,但是没有对国产设备防火墙分析.本次项目采用centos 7.2操作系统,e ...
- 华为防火墙如何配置双出口,特定IP段流量走指定出接口地址上网
环境: 华为USG6311E VRP ® Software, Version 5.170 (USG6300E V600R007C00SPC200) V200R007C00SPC091 电信宽带:拨号 ...
- 华为防火墙简介及其工作原理
防火墙作为一种安全设备被广泛使用于各种网络环境中,他在网络间起到了间隔作用.华为作为著名的网络设备厂商,2001年便发布了首款防火墙插卡,而后根据网络发展及技术需求,推出了一代又一代防护墙及安全系列产 ...
- 华为防火墙及它的工作原理
一.华为防火墙产品介绍 USG2000.USG5000.USG6000和USG9500构成了华为防火墙的四大部分,分别适合于不同环境的网络需求,其中,USG2000和USG5000系列定位于UTM(统 ...
- 华为防火墙(NGFW)的双机热备
目录 VRRP技术 VGMP协议 VGMP报文格式 VGMP组管理 HRP HRP心跳接口 双机热备的备份方式 实验 实验拓扑 实验说明 实验配置 实现网络高可靠性的一种技术 VRRP技术 虚拟路由冗 ...
- 华为防火墙VRRP双机热备的配置
双机热备 概念 一.华为双机热备的两种模式 二.相关术语 三.配置 概念 双机热备特指基于高可用系统中的两台服务器的热备(或高可用),因两机高可用在国内使用较多,故得名双机热备,双机高可用按工作中的切 ...
最新文章
- Linux RAR 安装和使用
- Floating Window 详解
- Java判断一个数是否是回文数
- 我的第五个网页制作:pre、html转义、abbr标签的使用
- 光脚丫学LINQ(005):数据表之间的联接查询
- oracle11g约束有哪几种状态,【简答题】数据完整性通常有哪几种类型, Oracle11g 通过哪些方式来进行数据完整性控制...
- Mysql存储结构B树与B+树与索引
- LeetCode 1153. 字符串转化(哈希)
- svn服务器搭建之备份3
- 如何将 hadoop1.1.2/1.2.1 源码关联到 Eclipse
- KITTI数据集解析
- SCDN如何有效防御CC攻击和DDOS攻击的
- SPSS实现神经网络(多层感知器)
- uni-app和H5页面使用支付宝登陆问题解决
- VS2015基于对话框的MFC倒计时器
- 树莓派 Retropie 4.4中文版使用说明 含roms资源
- M1 芯片打开软件提示:“XXXX” 因为出现问题而无法打开 怎么解决?
- MTK Secure Boot 2.1详细配置方案-终极版
- 商家自建流量池:10种微信引流的方法,值得学习社群营销的商家收藏 !
- 【共享经济】披着共享经济外衣的租赁经济