Hi All,
I am trying to write a shell script that does the following:
Looks through a configuration of a firewall (netscreen) that has the following general format:
Policy port sourceIP destinationIP direction etc. etc.
src IP address1
src IP address2
src IP address3
src IP address4
exit
I am trying to write a small script that will find a list of all the source IP addresses that are allowed explicitly by the firewall rule to the destination IP. The one odd thing about the configuration file is that the first source IP address that is allowed is on the same line as the destination, however all following source IP addresses are listed below that line. As you can see the rule is terminated by the exit command.
There are hundreds of configuration paragraphs, so I really just want to be able to pick one dst IP address and run a small script to extract that information, so a simple grep will not work.
I have a small shell script that does roughly the following:
while read line; do
if echo $line | cut -f 4 | grep "destinationIP" ; then
echo DST:dest IP
if echo $line | grep "src" ; then
echo SRC: src
if echo $line | grep "exit" ; then
exit
done
However that is not properly picking up the information.
Unfortunately I'm not in front of the actual computer with the config or script, but I can post the actual configuration file and the script that I do have if that's more helpful to make a concrete example.
Further I realize that Perl is probably the best tool for this, but I really want to do this in shell, partly for the sake of just doing it in shell.
Thank you for any help that you can give.
-jouell
I am trying to write a shell script that does the following:
Looks through a configuration of a firewall (netscreen) that has the following general format:
Policy port sourceIP destinationIP direction etc. etc.
src IP address1
src IP address2
src IP address3
src IP address4
exit
I am trying to write a small script that will find a list of all the source IP addresses that are allowed explicitly by the firewall rule to the destination IP. The one odd thing about the configuration file is that the first source IP address that is allowed is on the same line as the destination, however all following source IP addresses are listed below that line. As you can see the rule is terminated by the exit command.
There are hundreds of configuration paragraphs, so I really just want to be able to pick one dst IP address and run a small script to extract that information, so a simple grep will not work.
I have a small shell script that does roughly the following:
while read line; do
if echo $line | cut -f 4 | grep "destinationIP" ; then
echo DST:dest IP
if echo $line | grep "src" ; then
echo SRC: src
if echo $line | grep "exit" ; then
exit
done
However that is not properly picking up the information.
Unfortunately I'm not in front of the actual computer with the config or script, but I can post the actual configuration file and the script that I do have if that's more helpful to make a concrete example.
Further I realize that Perl is probably the best tool for this, but I really want to do this in shell, partly for the sake of just doing it in shell.
Thank you for any help that you can give.
-jouell