I'm continuing on a script on which the Monks here have helped this week. I've come up against another problem that I, as a Perl pre-novice, can't quite figure out. Up to this point, the script does what I want it to. A synopsis:
The script opens up the config of a PIX firewall and pulls out all of our IP addresses to a file, pix.out. Pix.out is then ran through the shell command 'sort -u' to eliminate all duplicate addresses, creating ns.in. Ns.in is then processed through the Nslookup.pm module to resolve all IP addresses to FQDNs. The output of the nslookup routine is pushed to a hash, %hosts with $ip as the key and $a, holding th FQDN, as the value. Now, I want to use the key and value in the hash to search all the IPs out of the PIX config and replace all of them with the appropriate FQDN. Another point about the PIX config- it will sometimes hold two different IP addresses per line. So, here is what I've tried now:
FQDN is the output file.
open INFILE, "longwood.pix";
open FQDN, ">fqdn.pix" or die "Can't open der finalen filen: $!";
@final = <INFILE>;
close INFILE;
while ( ($ip, $a) = each (%hosts)) {
foreach $line (@final) {
's/$ip/$a/g';
print FQDN @final;
}
}
close INFILE;
close FQDN;
The results of this have been nothing. If I put parentheses aroung the variables in the s///g regex, I end up with an ever growing file.
The end result we want to have is a copy of the orig PIX config with all the IPs substituted with FQDNs.
Thanks,
Monger
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.