PDA

View Full Version : email_addresses_v2.pl



Cyb3r_H4ck3r
11-24-2014, 02:59 PM
#!/usr/bin/perl
use strict;
# replace dot with "."
# replace AT with @
# remove extra spaces
sub normalize {
my $email=shift @_;
$email =~ s/([a-z0-9_\-]+)([ ]+[_]*dot[_]*[ ]+)/$1./gi;
$email =~ s/([a-z0-9_\-]+)[ ]+at[ ]+([a-z0-9_\-]+)/$1\@$2/gi;
$email =~ s/ //g;
return $email;
}

my $file = shift @ARGV;
my $ifh;
my $is_stdin = 0;
if (defined $file){
open $ifh, '<', $file or die "Could not open file $file";
} else {
$ifh=*STDIN;
$is_stdin++;
}

# undefine line separator to read entire content
my $old_sep=$/;
local $/=undef;
my $content=<$ifh>;
$/=$old_sep;

# parse all emails like:
# 1. [email protected] (no spaces)
# 2. email @ domain.com (spaces near @)
# 3. email AT domain.com (@ replaced with " at " case insensitive)
# 4. email @ domain _dot_ com (. replaced with " _dot_ " case insensitive)
# 5. email @ domain DOT com (. replaced with " DOT " case insensitive
print normalize($1)."\n" while $content =~ m/\<?([a-z0-9._\-]+([ ]*@[ ]*|[ ]+at[ ]+)([0-9a-z_\-]+(\.|[ ]+[_]*dot[_]*[ ]+))+[a-z]{2,4})\>?/gi;

l0OkIn
04-15-2015, 09:10 AM
any cmd? on hw to use it?