Difference between revisions of "Perl module chkIPadr"
From Teknologisk videncenter
m (New page: <source lang=perl> #Filnavn: ip.pm package ip; use base 'Exporter'; our @EXPORT_OK = qw(chkIPadr); use strict; use warnings; sub chkIPadr { my $ip = shift; if ( $ip =~ m/(^[1-9][0-9]*)...) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 25: | Line 25: | ||
1; #Et modul skal afslutte sandt (1) | 1; #Et modul skal afslutte sandt (1) | ||
</source> | </source> | ||
+ | [[Category:Perl]] |
Latest revision as of 08:50, 31 March 2010
#Filnavn: ip.pm
package ip;
use base 'Exporter';
our @EXPORT_OK = qw(chkIPadr);
use strict;
use warnings;
sub chkIPadr {
my $ip = shift;
if ( $ip =~ m/(^[1-9][0-9]*)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) {
if (!(($1<224)&($2<256)&($3<256)&($4<256))) {
return(0);
} else {
return($ip);
}
}
#Hvis det ikke er en IP adresse er det måske et DNS-navn
if ( my $packedIP=gethostbyname( $ip )) {
my $realIP = inet_ntoa($packedIP);
return($realIP);
} else {
return(0);
}
}
1; #Et modul skal afslutte sandt (1)