1, demand
Want to check whether an ip address in each firewall, network equipment security policies; network engineers need to be familiar with the traditional model of different products command
log in to multiple devices to view the ip address policy. Fool-operation achieved by the python;
2, python test script principle
- Check ip address is reasonable
- ip address query
# -*- coding: utf-8 -*-
# Aduthor:CCIP-Ma
import os
import re
import sys
#print(os.listdir(r'E:\filetest'))
import_ip= input('查询的ip地址:')
def checkip(hostip):
pat = re.compile(r'([0-9]{1,3})\.')
r = re.findall(pat,hostip+".")
if len(r)==4 and len([x for x in r if int(x)>=0 and int(x)<=255])==4:
pass
else:
print("错误")
sys.exit()
checkip(import_ip)
path=r'E:\a'#配置存放文件目录
def FindIp(ip):#查询ip
for file in os.listdir(path):
f_path=path+"\\"+file
#print(f_path)
f=open(f_path,'r',encoding='utf-8')
for line in f:
if ip in line:
print('''-----------info---------
策略:%s
节点名称:%s
'''%(line,file))
else:
pass
print('没有该%s地址的策略'%ip)
FindIp(import_ip)
x
1
# -*- coding: utf-8 -*-
2
# Aduthor: Crcif-mother
3
import os
4
import re
5
import sys
6
#print (os.listdir (R ': \ FileTest'))
7
import_ip = INPUT ( 'IP address query:' )
8
def checkip(hostip):
9
pat = re.compile(r'([0-9]{1,3})\.')
10
r = re.findall(pat,hostip+".")
11
if len(r)==4 and len([x for x in r if int(x)>=0 and int(x)<=255])==4:
12
pass
13
else:
14
Print ( "Error" )
15
sys.exit()
16
checkip(import_ip)
17
path = r'E: \ A ' # configuration file storage directory
18
DEF FindIp ( ip ): # ip inquiry
19
for file in if . listdir ( path ):
20
f_path=path+"\\"+file
21
#print(f_path)
22
f=open(f_path,'r',encoding='utf-8')
23
for line in f :
24
if ip in line:
25
print('''-----------info---------
26
Strategy:% s
27
Node Name:% s
28
'''%(line,file))
29
else:
30
pass
31
Print ( '% s does not address the policy' % IP )
32
33
34
35
FindIp(import_ip)
36