Thread hostname checking (11 answers)
Opened by esskar at 2004-08-04 02:30

esskar
 2004-08-06 01:29
#85354 #85354
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
hab es jetzt mal so gelöst:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use constant REGEXP_HOSTNAME      => qr/^([\w\-.]+)$/;
use constant REGEXP_IPADDR        => qr/^((?:(?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})[.](?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})[.](?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})[.](?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})))$/;

sub valid_hostname
{
  my $value = shift;

  return 0 unless $value =~ REGEXP_HOSTNAME;
return 0 unless index($value, ".") > 0;

  my @parts = split/\./, $value;
  my $valid = @parts;

  foreach my $label (@parts)
  {
     $valid = 0 if (length $label > 63) or ($label =~ m!^\-!) or ($label =~ m!\-$!);
     last unless $valid;
  }

  $valid = 0 if $parts[-1] =~ m!^\d.*!;

  return $valid;
}

sub valid_ipaddr
{
  my $value = shift;
  return $value =~ REGEXP_IPADDR;
}

sub valid_host
{
  my $value = shift;
  return valid_hostname($value) || valid_ipaddr($value);
}


meinungen erwünscht!\n\n

<!--EDIT|esskar|1091741673-->

View full thread hostname checking