Perl IP to Domain Name converter.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

I find a Perl IP to Domain Name converter from the following url:

I copy the code to a perl script named, when I
run it I meet the errors like this:

Quoted text here. Click to load it

$ ./
Global symbol "$infilePlacing" requires explicit package name at
./PerlIP2Domain line 28.
syntax error at ./ line 31, near "=)"
syntax error at ./ line 41, near "}"
Execution of ./ aborted due to compilation errors.

Quoted text here. Click to load it

Here is the perl code:

#!/usr/bin/perl -w
use Socket;
use Getopt::Std;
use strict;
# simple script to resolve ip addresses in a web log file
# into host names
# typical logline:
# - - [11/Feb/2002:13:29:14 +0000] "GET
/phppolls/phppolls.php?poll_action=viewPoll&poll_id=22 HTTP/1.1" 200
5394 "" "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.0)"
my %options;
my ($infile, $outfile, %cached_ips, $line, @lines, $tmp, @bits,
$newline, @newlist);
my $progname=$0;
# use basename only:
# parse our arguments:
getopts("dho:vf:", %options);
# if no infile, print usage:
if(!$options || $options)
# if no outfile given, default to $infile."new":
# attempt to open infile:
open(IN, $infile) || die("Unable to open file: $infile");
# attempt to open outfile:
open(OUT, ">$outfile") || die("Unable to open file: $outfile");
        print "Taking input from: $infilePlacing output to: $outfile";
sleep 2;
        # get the ip and the date parts from the lines:
        @bits=split(" ", $line);
         if($options){ print $bits[0].""; }
         # put line back together:
        print OUT $newline=(join(" ", @bits)."");
         # if verbose set, print each line out to stdout:
        if($options){print $newline;}
 if($options){ print "".%cached_ips; }
 sub resolve_ip{
         foreach $this_ip (keys %cached_ips){
                # if this ip has already been cached, return the name,
otherwise resolve and cache this ip/name:
                $_[0] eq $this_ip ? return($cached_ips) :"";
 sub cache_ip{
        my $name;
         # attempt to resolve ip:
        if( ($name= gethostbyaddr(inet_aton($_[0]), AF_INET)) eq "" ){
        } else {
 sub usage{
        die [-o ]
     -f REQUIRED - name of input log file to resolve dotted ip
                           addresses to canonical names.
    -o OPTIONAL - name of output file to dump results to.
                           Defaults to .new.
    -v OPTIONAL - verbose; prints out each logfile line as it
 is parsed.


Any hints on this issue?

.: Hongyi Zhao [ hongyi.zhao AT ] Free as in Freedom :.

Re: Perl IP to Domain Name converter.

Quoted text here. Click to load it

If there are syntax errors, then what you have is not a Perl program...

Quoted text here. Click to load it

This is the first mention of $infilePlacing in the program.

It has not been declared, which violates the "use strict" pragma and
produces the first error message above.

Furthermore, it has not been given any value, so outputting it is not likely
to be productive anyway.

Quoted text here. Click to load it

Perhaps this was meant to be:

    while ($line = <IN>) {

Clearly this program has never ever been executed.

There are lots of bad "programs" on the wild interweb, you have found one
of them.

Even without the syntax errors, I can say that this was not written
by a good Perl programmer...

Quoted text here. Click to load it

What you have found is garbage.

Keep looking.

Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Site Timeline