in reply to perl to convert text list of ip address to a name

Here is the code I use for IP to HostName:
use Socket; # For Binary-> IP dot quad etc... use Net::Whois::IANA; # For IP -> Name # Get IP addr # Call the sub below, and print value sub Get_Whois_Name { my $ip = shift; my $Save_ = $_; # The WhoIs module messes with $_ (BUG!!) # Save current value for restore upon exit. ##print "LOOKING FOR $ip ===="; my $iana = new Net::Whois::IANA; $iana->whois_query(-ip=>$ip); my $name = $iana->descr(); if ($name =~m/not allocated/){ $name = "Country=" .$iana->country() ."+Net=" . $iana->netname(); } #Zap commas in name $name =~s/\,/ /g; $_ = $Save_; # Restore return $name; } ##########################################

Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarntees offense.

Replies are listed 'Best First'.
Re: Re: perl to convert text list of ip address to a name
by tilly (Archbishop) on May 17, 2004 at 23:50 UTC
    Why get rid of commas?
      They asked for a Comma Separated List. The author just took the quick route of removing commas to make a "clean" name. You could also find if there is a comma in the name and enclose the complete name in double quotes.
        That is what I wanted to verify before pointing out that you also need to "zap" returns as ". Alternately you just encode your CSV properly and you don't have to mangle any data.