Changeset 360 for trunk/ddt


Ignore:
Timestamp:
Sep 14, 2018, 9:48:42 PM (6 years ago)
Author:
g7moreau
Message:
  • Try to have better ip range dns check
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r359 r360  
    27272727               my $ip_address = inet_ntoa($packed_ip);
    27282728               if ($ip ne $ip_address) {
    2729                   print "Error: bad IP for reverse DNS on $dns_hostname_fq / $ip\n";
     2729                  print "Error: bad IP $ip for reverse DNS on $dns_hostname_fq\n";
    27302730                  next LOOP_ON_COMPUTER;
    27312731                  }
     
    27612761      my @ip_check;
    27622762      LOOP_ON_SECTOR:
    2763       for my $sector_current (@{$computer_db->{'dset'}}) {
    2764          next LOOP_ON_SECTOR if not exists $computer_db->{'dset'}{'ip_range'};
     2763      for my $sector_current (keys %{$computer_db->{'dset'}}) {
     2764         next LOOP_ON_SECTOR if not exists $computer_db->{'dset'}{$sector_current}{'ip_range'};
    27652765
    27662766         LOOP_ON_CIDR:
    2767          for my $ip_range (@{$computer_db->{'dset'}{'ip_range'}}) {
     2767         for my $ip_range (@{$computer_db->{'dset'}{$sector_current}{'ip_range'}}) {
    27682768
    27692769            LOOP_ON_IP:
    27702770            for my $ip (NetAddr::IP->new($ip_range)->hostenum()) {
    27712771               print "$ip\n";
     2772               
     2773               my $dns_hostname_fq = scalar gethostbyaddr(inet_aton($ip), AF_INET);
     2774               my ($dns_hostname) = split /\./, $dns_hostname_fq;
     2775
     2776               # Verify reverse return same IP
     2777               my $packed_ip = scalar gethostbyname($dns_hostname_fq);
     2778               if (defined $packed_ip) {
     2779                  my $ip_address = inet_ntoa($packed_ip);
     2780                  if ($ip ne $ip_address) {
     2781                     print "Error: bad IP $ip for reverse DNS on $dns_hostname_fq\n";
     2782                     #next LOOP_ON_IP;
     2783                     }
     2784                  }
     2785
     2786               # Verify direct return same host
     2787               LOOP_ON_COMPUTER:
     2788               for my $computer (@{$computer_db->{$sector_current}) {
     2789                  my ($mac_address, $attribute) = %{$computer};
     2790
     2791                  next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip;
     2792
     2793                  next LOOP_ON_IP if $attribute->{'hostname'} eq $dns_hostname;
     2794                 
     2795                  print "Error: DNS bad host $dns_hostname for IP $ip\n";
     2796                  next LOOP_ON_IP;
     2797                  }
     2798
     2799               # Declare in DNS but not in DDT
     2800               print "Error: DNS host $dns_hostname with IP $ip not declare in DDT database\n" if $dns_hostname ne '';
     2801               # Normally never arrive here
     2802
     2803               #if ($computer_db->{$sector_current}{}$attribute->{'hostname'} ne $dns_hostname) {
     2804               #   print "$mac_address ($sector_current) $ip - $dns_hostname / $attribute->{'hostname'} # $attribute->{'comment'}\n";
     2805               #   next LOOP_ON_IP;
     2806               #   }
    27722807               }
    27732808            }
Note: See TracChangeset for help on using the changeset viewer.