Senthil Murugan's Blog

Home » Educational » Finding IP Addresses accessing the mail server

Finding IP Addresses accessing the mail server

I’m wanting to keep only the IP addressees in a huge file that look like this using Notepad++ I can’t figure out a good regex to accopmlish this. Any help would be appreciated.

9/9/2099 09:00 PM | UA: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like 
GeckoChrome/34.0.1847.116 Safari/537.36 | IP: 61.252.241.65
HOST: 61-252-241-65.hlrn.qwest.net | REFERRER: http://www.google.com/

9/9/2099 03:00 PM | UA: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/34.0.1847.116 Safari/537.36 | IP: 71.222.254.49
HOST: 71-222-254-49.hlrn.qwest.net | REFERRER: http://www.google.com/

Should become

61.252.241.65
71.222.254.49

 

You can use this (check the dotall mode: “. matches newlines”):

find: .*?((?:\d{1,3}\.){3}\d{1,3}\r?\n)|.+
replace: $1

.*? will match all characters until the next IP address (in the group 1)

At the end, when there is no more IP addresses, the first part of the pattern will fail, and .+ takes all the characters until the end. The content of the capture group 1 is preserved.

Thanks to Stackoverflow

http://stackoverflow.com/questions/23707270/notepad-keep-only-ip-addresses

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: