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.

I need to quickly test the whole C class IP address range.

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


In reply to Non-empty strings treated as null?!! by watkin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.