统计防火墙会话中公网地址个数

防火墙会话如下:

 msn-stun  VPN: public --> public  Remote 10.16.150.114:61721[192.160.224.209:7060] --> 112.60.24.54:3478 
 http  VPN: public --> public  Remote 10.1.32.121:58026[192.160.226.99:2603] --> 39.135.65.111:80 
 udp  VPN: public --> public  Remote 10.16.137.152:45439[192.160.227.210:48956] --> 120.229.128.134:6045 
 https  VPN: public --> public  Remote 10.16.87.237:48610[192.160.224.53:18192] --> 183.240.176.207:443 
 dns  VPN: public --> public  Remote 10.17.182.54:2348[192.160.224.234:8048] --> 192.179.38.7:53 

代码如下:

""" 

python

import re
import os
count_224=0
count_225=0
count_226=0
count_227=0
counts=0
with open("HWE9000EX-189-20231017-170012.txt","r",encoding='utf8') as f:

    for line in f:
        ip_address=re.findall(r".*?(192.\d+.\d+.\d+:\d+).*",line)
#        ip_address=re.findall(r".*\[(192.\d+.\d+.\d+:\d+)\].*",line)        
        counts=counts+1
        if ip_address == []:#不能写成if ip_address is None:
            continue
        elif "192.160.224." in ip_address[0]:
                            count_224 = count_224+1
        elif "192.160.225." in ip_address[0]:
                            count_225 = count_225+1 
        elif "192.160.226." in ip_address[0]:
                            count_226 = count_226+1
        elif "192.160.227." in ip_address[0]:
                            count_227 = count_227+1
print(count_224+count_225+count_226+count_227,"224段:"+str(count_224),"225段:"+str(count_225),"226段:"+str(count_226),"227段:"+str(count_227),"总条目:"+str(counts))
#
——————————————————————————————————————————————————————————————
import re
import os
count_224=0
count_225=0
count_226=0
count_227=0
counts=0
with open("HWE9000EX-189-20231017-170012.txt","r",encoding='utf8') as f:

    for line in f:       
        if "192.160.224." in line:
                            count_224 = count_224+1
        elif "192.160.225." in line:
                            count_225 = count_225+1 
        elif "192.160.226." in line:
                            count_226 = count_226+1
        elif "192.160.227." in line:
                            count_227 = count_227+1                       
print(count_224,count_225,count_226,count_227)

"""

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值