
mant1s
New User
Jul 5, 2011, 2:01 PM
Post #1 of 3
(5240 views)
|
Extracting an IPv4 address from line
|
Can't Post
|
|
Hi All, I'm wondering what I should do to extract the second IP address from a log file I have. My log file looks like:
[03072011 13:32:01] connection connection.c:3880-message: connection 0x8fa0fe0 accept/tcp/none [130.55.252.94:21->184.105.172.67:34627] state: none->established I only want to snag the address 184.105.172.67. Currently I'm using the following function to narrow it down but it doesn't seem to be working. Any pointers!?
##Loop to extract the ips foreach(@msg3880) { my ($selected) = $_; if ($selected =~ m/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) { my $ip = $1 << 24 | $2 << 16 | $3 << 8 | $4; print $ip; } } Note @msg3880 is an array that holds all the lines above. Any help would be appreciated!
|