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:
Post deleted by yanivr78

 



yanivr78
Novice

Mar 8, 2013, 4:56 AM

Post #1 of 5 (493 views)
Post deleted by yanivr78

 


Kenosis
User

Mar 8, 2013, 9:52 AM

Post #2 of 5 (486 views)
Re: [yanivr78] matching 2 regex IP [In reply to] Can't Post

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)


yanivr78
Novice

Mar 8, 2013, 10:29 AM

Post #3 of 5 (482 views)
Re: [Kenosis] matching 2 regex IP [In reply to] Can't Post

Thanks Kenosis !
didnt knew about that option.
but just to elaborate,
the problem is that I cannot use cpan modules on the code (its an isolated machine with no internet connection).

Any chance to accomplish that without Regexp::Common ?

when I try with index, no matter what I give it - it gets confused with the first IP.... :/


Laurent_R
Veteran / Moderator

Mar 8, 2013, 11:03 AM

Post #4 of 5 (481 views)
Re: [yanivr78] matching 2 regex IP [In reply to] Can't Post

Just download the module and copy the relevant regexes from there.


Kenosis
User

Mar 8, 2013, 4:56 PM

Post #5 of 5 (474 views)
Re: [yanivr78] matching 2 regex IP [In reply to] Can't Post

You're most welcome!

You can use the following regex, but it's not a robust as the Module's:

Code
/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g


 
 


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

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