[WpProQuiz 3]
[WpProQuiz_toplist 3]
Perl quiz on Operators
Learning through sharing
Our team always face email existence problem when they try to:
Well it’s not possible to know 100% whether given e-mail address exists in real or not but it will be handy in majority of the cases. You can do it manually also if you are in Linux box using host or nslookup and telnet command. I would prefer host command for this purpose.
How it works:
Here many things came into the picture while testing various mail ids from various mail handlers. I will discuss it under “possible ways of failures”
Steps to check the email existence manually
1. Get the mail id to verify (we can get domain-name from this format to use it in our next step userid@domain-name . For ex:admin@aliencoders.org)
2. Either use nslookup command or host command to get mail server address (Lists of mx records from DNS)
a. Using nslookup:
nslookup –type=mx domain-name
b. Using host :
host –t mx domain-name
3. Get the least digital value’s mx record to use it in telnet
a. telnet mxrecord port-no i.e. telnet mail.aliencoders.org 25
b. Once connected use SMTP commands to know if email id exists or not. It will return 250 as a return code with OK or Accepted. Depending upon mail server configuration and Linux flavors too.
Let’s see it practically with all combination of commands, inputs and outputs š
Output from nslookup (it will show many more things which I have not shown here)
$ nslookup -type=mx gmail.com
Non-authoritative answer:
gmail.com mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 5 gmail-smtp-in-v4v6.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
Output from host command ( I prefer this over nslookup )
$ host -t mx gmail.com
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in-v4v6.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
Get the value which has lowest ranked digit. In this case it is 5 so take gmail-smtp-in-v4v6.l.google.com for our purpose
Either use host or nslookup for the first stage.
Telnet outputs:
Step 1
telnet gmail-smtp-in-v4v6.l.google.com 25
Trying 173.194.77.27…
Connected to gmail-smtp-in-v4v6.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP hk4si16050652obc.168
Step 2 (type helo, if it didn’t work try helo hi, if it didn’t work too try ehlo then )
helo
250 mx.google.com at your service
Step 3 (type any valid email id. Invalid email id will say ok but after rcpt to it will throw an error and don’t skip this step)
mail from: <sanjeev@aliencoders.org>
250 2.1.0 OK hk4si16050652obc.168
Step 4 (You need to provide email which needs to be verified. Ok means it may exists. Not 1005 guaranteed on existence but we can infer that this email id may work)
rcpt to: <jassics@gmail.com>
250 2.1.5 OK hk4si16050652obc.168
Telnet outputs on failure (Various reasons are there)
1. Network is unreachable. (sometimes it is reachable form one host but not from others)
telnet gmail-smtp-in-v4v6.l.google.com 25
Trying 74.125.127.26…
telnet: connect to address 74.125.127.26: Connection timed out
Trying 2001:4860:8005::1b…
telnet: connect to address 2001:4860:8005::1b: Network is unreachable
telnet: Unable to connect to remote host: Network is unreachable
2. Error at mail from:<mail-id> :
3. If email id exists but it doesn’t show up 250/ok then below reasons may justify this:
Steps to check email existence using Perl
Good thing with this script is:
Here is the fully working Perl script
Why still this trick doesn’t assure 100% proof that email id exists or not?
There can be many reasons for not trusting on this script or the above said manual steps. Best way is to send an email to the given email id. If it bounced back, means it doesn’t exist or can’t be delivered. (I chat with a person in gtalk but can’t send an email to that person. Strange isn’t it).
Note: This was just for educational purpose and found helpful for web masters or admins. Don’t use it as spam stuffs, you IP address and your mail id will be blacklisted. Like admin@aliencoders.org has been blacklisted from various mail servers.
Millennium Bug or y2038 Bug in Unix Machine This post is dedicated to backend programmers mainly and especially who are involved with *nix machine(s) or […]
This is one of the questions asked in many Perl related job interviews. See the question here: http://www.aliencoders.org/content/interview-questions-perl-freshers-and-experienced
There will be some situations when you will need to know about installed modules, its version or you may need to check if required module is installed or not with mentioned version or higher than that.
1. To list all installed Perl modules using perl script
[perl]
#!/usr/bin/perl #change the path with your perl location
use strict;
use warnings;
use ExtUtils::Installed; # By default this module will be available in Perl
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module) || “Version Not Found.”;
print “$module version=$version \n”;
}
[/perl]
2. To list installed Perl modules using command line in Linux box
Try instmodsh command in linux box
and then type l to list modules or m to give particular module name or q to quit
[code] $ instmodsh[/code]
Output:
[code]Available commands are:
l – List all installed modules
m – Select a module
q – Quit the program
cmd?[/code]
At cmd? prompt type l to list all installed modules:
[code]cmd? l[/code]
Output:
[code]Installed modules are:
Archive::Tar
CPAN
Compress::Zlib
MIME::Lite
Module::Build
Net::Telnet
PAR::Dist
Perl
Spiffy
Test::Base
Test::Simple
XML::Simple
cmd?
[/code]
This command itself is a perl script that use ExtUtils::Installed module. Try following command to see its source code:
[code]$ vi $(which instmodsh)[/code]
For more details, visit this link: http://perldoc.perl.org/instmodsh.html
3. To compare and check installed Perl modules with respect to given modules with its version
[perl]
#!/usr/bin/perl
use strict;
use warnings;
my @modules = ([‘SOAP::Lite’, 0.50],
[‘IO::Socket’, 0],
[‘HTML::Parser’, 3.26],
[‘LWP’, 5.65],
);
print “\n”,
“==========================\n”,
“Testing for the given Perl modules\n”,
“===========================\n”;
for my $arr_ref (@modules) {
my($mod, $ver) = @$arr_ref;
print “$mod” . ($ver ? ” (version >= $ver)” : “”) . “\n”;
eval(“use $mod” . ($ver ? ” $ver;” : “;”));
if ($@) {
my $msg = $ver ?
“\tEither it doesn’t have $mod installed,\n” .
“\tor the version that is installed is too old.\n” :
“\tIt does NOT have $mod installed.\n”;
print “$msg\n”;
}
else {
print “\tYour system has $mod installed ” .
“with version @{[ $mod->VERSION ]}\n\n”;
}
}
print “Module Testing Done!\n”;
[/perl]
Note: If you are putting module name dynamically, then use @{[ $mod->VERSION ]} for version number
else $Module-Name::VERSION ex: $SOAP::Lite::VERSION
[perl]
print “SOAP::Lite Version is “. $SOAP::Lite::VERSION.”\n”;
#or
print “$mod version is @{[ $mod->VERSION ]} \n”;
[/perl]
4. To list Perl modules that comes preinstalled with the standard Perl package and installed from outside
[perl]
perldoc perlmodlib #lists all the modules that come with standard Perl package already
perldoc perllocal #lists all modules that is installed from outside
[/perl]
Both modules reveal lots of information about each installed modules like installation date, directory, module version etc.
Subscribe now to keep reading and get access to the full archive.
Visitor Rating: 1 Stars
Visitor Rating: 5 Stars