# for just DottedQuadToLong(): use Net::IP; print Net::IP->new("24.72.30.83")->intip; # for both directions: use Net::IP qw/:PROC/; print ip_bintoint(ip_iptobin("24.72.30.83",4)); print ip_bintoip(ip_inttobin("407379539",4),4);
sub DottedQuadToLong { my $ip_str = shift; return 0 unless $ip_str =~ /^\s*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.( +\d{1,3})\s*$/; my $ip = 0; foreach my $quad ($1,$2,$3,$4){ return 0 if ($quad > 255); $ip = $ip * 256 + $quad; } return $ip; }
In reply to Re: IP address - long to dottedquad to long
by davidrw
in thread IP address - long to dottedquad to long
by ruzam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |