watkin has asked for the wisdom of the Perl Monks concerning the following question:
Dear perlmonks,
As a novice perl programmer, could someone help me solve this seemingly impossible apparent error with my perl interpreter (running on my somewhat dated Linux Mint 14 Nadia system). (I am trying to ban FORUM SPAMMERS from posting to a Drupal content-managed web-site I help administer.)
Essentially, the code, listed below erroneously interprets two clearly non-null strings as being null.
#!/usr/bin/perl use Net::Nslookup; my ($name, $ipAddr); foreach (@ARGV) { $name = nslookup(host => $_, type => "PTR"); if($name != "") { print("looking up ... $name ..."); $ipAddr = nslookup(host => $_, type => "A"); } else { print("NOT looking up ... $name ..."); } print "$_ $name $ipAddr\n"; }
The command-line I use is:
nsl.pl 109.163.234.7 136.169.192.25 174.140.166.22 178.137.180.11 188. +126.75.245 204.45.103.68
The output is:
NOT looking up ... edwardsnowden0.torservers.net ...109.163.234.7 edwa +rdsnowden0.torservers.net NOT looking up ... ...136.169.192.25 NOT looking up ... ...174.140.166.22 looking up ... 178-137-180-11-broadband.kyivstar.net ...178.137.180.11 + 178-137-180-11-broadband.kyivstar.net NOT looking up ... c-188-126-75-245.anonymous.at.anonine.com ...188.12 +6.75.245 c-188-126-75-245.anonymous.at.anonine.com NOT looking up ... ...204.45.103.68
Reverse (PTR) lookups of 109.163.234.7 and 188.126.75.245 give me respectively edwardsnowden0.torservers.net and 178-137-180-11-broadband.kyivstar.net , which are clearly NON-NULL strings, yet the test in my perl program indictes that those strings are NULL !?
Can someone suggets to me how I can fix this apparent problem with perl? I truly need a more efficent way of querying these IP address than with the linux nslookup command-lien utility.
Thank you for your attention,
watkin
Original content restored above by GrandFather
Dear perlmonks,
Thank you, tangent.
I'll try your cleaned up version and let you know how it goes.
... and, thank you, davido.
The 'eq' operator in place of '!=' has fixed the problem. I'll be sure to include the use warnings; statement in my perl scripts from now on.
Whilst use of the perl script will be more efficient than the nslookup linux utility program, what I really need is a means to quickly test the whole IP C class network containing the host (e.g. 136.169.192.25) from which the forum spam was posted (i.e. all IP addresses from 136.169.192.0 to 136.169.192.255) I would like to be able to quickly tell whether or not that network is known to the global DNS/Bind database. If it is not, I can quickly add the whole network (indicated by '136.169.192.%' with the wild '%'character) to the drupal/Mysql 'access' table and set the "access type" field to 'deny'.
Havingto test each of the 256 IP addresses in a C Class range would take a a lot of efrort even with the perl script
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Non-empty strings treated as null?!!
by davido (Cardinal) on Feb 12, 2014 at 23:49 UTC | |
|
Re: Non-empty strings treated as null?!!
by tangent (Parson) on Feb 13, 2014 at 00:03 UTC | |
|
Re: Non-empty strings treated as null?!!
by tweetiepooh (Hermit) on Feb 13, 2014 at 12:26 UTC |