CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [yanivr78] matching 2 regex IP: Edit Log



Kenosis
User

Mar 8, 2013, 9:52 AM


Views: 462
Re: [yanivr78] matching 2 regex IP

Consider using Regexp::Common to capture the IPs:

Code
use strict; 
use warnings;
use Regexp::Common qw /net/;

while (<DATA>) {
if ( my ( $source, $destination ) = (/($RE{net}{IPv4})/g)[ 1, 2 ] ) {
print "$source -> $destination\n";
}
}

__DATA__
Dec 4 20:25:21 10.85.254.10 %ASA-6-106100: access-list inside permitted tcp inside/10.80.20.25(42940) -> pscdmz/155.16.61.33(3181) hit-cnt 1 first hit [0xffe8f8cb, 0x75d65ece]
Dec 4 20:25:22 10.85.254.10 %ASA-6-106100: access-list inside permitted tcp inside/155.16.61.33(42940) -> pscdmz/10.80.20.25(3181) hit-cnt 1 first hit [0xffe8f8cb, 0x75d65ece]

Output:

Code
10.80.20.25 -> 155.16.61.33 
155.16.61.33 -> 10.80.20.25

Hope this helps!

Edit: Have placed the regex in a conditional, just in case a line exists w/o the IPs.


(This post was edited by Kenosis on Mar 8, 2013, 4:54 PM)


Edit Log:
Post edited by Kenosis (User) on Mar 8, 2013, 4:50 PM
Post edited by Kenosis (User) on Mar 8, 2013, 4:54 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives