
Notepad++ に置き換える方法を見つけようとしてたくさん読みましたが、結局どこにも行き着かないようです。
以下は、別の言語に変更する Juniper Config の例です。
set policy id 3016 from "CSA" to "Untrust" "1.1.1.1/32" "2.2.2.2/32" "SSH" permit log
set policy id 3016
set dst-address "3.3.3.3/32"
exit
!
set policy id 3053 name "Footprints" from "Untrust" to "CSA" "Blocked Addresses" "Any" "ANY" deny log
set policy id 3053
exit
これを Fortinet 言語に変更したいのですが、このプロセスを開始するには、特定の変数を検索する必要があります。変更する必要がある部分は次のとおりです。
set policy id 3016 from "CSA" to "Untrust" "1.1.1.1/32" "2.2.2.2/32" "SSH" permit log
set policy id 3016
set dst-address "3.3.3.3/32"
exit
!
set policy id 3053 name "Footprints" from "Untrust" to "CSA" "Blocked Addresses" "Any" "ANY" deny log
set policy id 3053
exit
に
edit 0
set srcintf "CSA"
set dstintf "Untrust"
set srcaddr "1.1.1.1/32"
set dstaddr "2.2.2.2/32" "3.3.3.3/32"
set action accept
set schedule "always"
set service "SSH"
set fsso disable
set nat enable
next
edit 0
set name "Footprints"
set srcintf "Untrust"
set dstintf "CSA"
set srcaddr "Blocked Addresses"
set dstaddr "all"
set action accept
set schedule "always"
set service "ALL"
set fsso disable
set nat enable
next
そこで、まずは以下のことを試してみました。
検索(set policy id (.+))
と置換edit 0
- これにより、すべてが強調表示され、編集が 0 だけ残った空の構成が残るようです。
(set policy id *)
次に、検索と置換を試みましたedit 0
- これにより、すべてが残りますが、以下のように変更されます: (基本的に、XXXXの前に0が挿入されます
edit 03016 from "CSA" to "Untrust" "1.1.1.1/32" "2.2.2.2/32" "SSH" permit log set policy id 3016 set dst-address "3.3.3.3/32" exit
何時間も節約できるので、どんな助けでも大歓迎です!!!!
答え1
私の意見では、お気に入りのスクリプト言語でスクリプトを書くべきです。
しかし、この作業を本当に Ntepad++ で実行したい場合は、正規表現によるソリューションがあります。ご覧のとおり、正規表現と置換は少し複雑で、維持するには十分な知識が必要です。
Ctrl+H
検索対象:
set policy id \d+ (?:(?:(?!exit).)*?name (".+?"))?(?:(?!exit).)*?from (".+?")(?:(?!exit).)*?to (".+?")(?:(?!exit).)*?("\d{1,3}(?:\.\d{1,3}){3}/\d+"|"[\w ]+") ("\d{1,3}(?:\.\d{1,3}){3}/\d+"|"[\w ]+") (".+?")(?:(?:(?!exit).)*?set dst-address (".+?"))?(?:(?!exit).)+?exit
と置換する:
edit 0\n\t(?1set name $1\n\t:)set srcintf $2\n\tset dstintf $3\n\tset srcaddr $4\n\tset dstaddr $5(?7 $7:)\n\tset action accept\n\tset schedule "always"\n\tset service $6\n\tset fsso disable\n\tset nat enable\nnext
チェック マッチケース
チェック 包み込む
チェック 正規表現
チェック
. matches newline
Replace all
Find All in Current Document
説明:
set policy id \d+ # literally and digits for id
(?: # non capture group
(?:(?!exit).)*? # 0 or more any character but not the word "exit"
name (".+?") # name is captured in group 1
)? # end group, optional
(?:(?!exit).)*? # 0 or more any character but not the word "exit"
from (".+?") # from is captured in group 2
(?:(?!exit).)*? # 0 or more any character but not the word "exit"
to (".+?") # to is captured in group 3
(?:(?!exit).)*? # 0 or more any character but not the word "exit"
("\d{1,3}(?:\.\d{1,3}){3}/\d+"|"[\w ]+") # group 4, src IP or literal like "Blocked Addresses"
("\d{1,3}(?:\.\d{1,3}){3}/\d+"|"[\w ]+") # group 5, dst IP or literal like "Any"
(".+?") # group 6, service
(?: # non capture group
(?:(?!exit).)*? # 0 or more any character but not the word "exit"
set dst-address # literally
(".+?") # group 7, 1 or more any character, not greedy
)? # end group, optional
(?:(?!exit).)*? # 0 or more any character but not the word "exit"
exit # literally
交換:
edit 0\n\t # edit 0 followed by linefeed and tabulation
(?1 # if group 1 exists, (name)
set name $1\n\t # print the name (group 1)
: # else
# nothing
) # end if
set srcintf $2\n\t # and so on ...
set dstintf $3\n\t
set srcaddr $4\n\t
set dstaddr $5
(?7 $7:)\n\t
set action accept\n\t
set schedule "always"\n\t
set service $6\n\t
set fsso disable\n\t
set nat enable\n
next
スクリーンキャプチャ(前):
スクリーンキャプチャ(後):
完全な説明が見つかりますここ