Hi all!

Ive got a problem performing IP address operations using Net::IP.

Here is what i need: I have to translate an IP address (for example, 10.0.1.3) into an integer value (for example, 167772419), and translate an integer value to an ip (167772419 to 10.0.1.3). I did:

use Net::IP qw(:PROC); my $ipaddr = '10.0.1.3'; my $ip = new Net::IP($ipaddr) or die (Net::IP::Error()); my $int = $ip->intip(); print "Integer value of IP $ipaddr: $int\n";

And it prints:
Integer value of IP 10.0.1.3: 167772419

Which is correct. But the reverse operation:

use Net::IP qw(:PROC); + + my $intaddr = 167772419; my $binaddr; eval{ $binaddr = ip_inttobin($intaddr); }; die "Error: $@" if($@); !defined($binaddr) and print "Binary not defined\n"; print "Binary value of integer $intaddr: $binaddr\n";


Prints:

Binary not defined
Binary value of integer 167772419:

Thus, i dont know how to transform an integer into a binary, and a binary into an ip, which is the only way i currently know.

Any idea on how to deal with this?
Thank you

In reply to IP operation trouble by fauria

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.