problems with logical && (and) statement



Hi,



I have been working on a writing a script to compare host information from
two different sources looking for differences. So far it is working fairly
well except the final logical && statement seems to fail. The two things I
am trying to check for is if the host is on the same network in both lists,
and then I am checking to see if it is the same subnet in both lists. This
is the particular line that is failing:

if(($dhcp{$wrkst}-{network} eq $ipdb{$wkrst}->{network}) &&
($dhcp{$wrkst}->{subnet} eq $ipdb{$wkrst}->{subnet}))



And here is the script in its entirety so far.



#!/usr/bin/perl

system "clear";

use Text::DHCPparse;

my $return;

my %dhcp;

my %ipdb;

$return = leaseparse('dhcpd.leases');

foreach (keys %$return) {

($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30",
$return->{$_});

my ($range) = $ip =~ /(\d{1,3})$/;

my ($network) = $ip =~
/^(\d{1,3}\.\d{1,3}\.\d{1,3})/;

if ($range >= 128) {

$dhcp{$name} = { ip => $ip,

mac => $mac,

subnet => hi,

network => $network,}


} else {

$dhcp{$name} = { ip => $ip,

mac => $mac,

subnet => low,

network => $network,}

}

}

my $ipdb_hosts = 'hosts.txt';

open (IN, $ipdb_hosts);

while ($line = <IN>) {

chomp $line;

next if ($line =~ /^\s*#/);

my(@host_array) = split / /, $line;

my $name = $host_array[2];

my $ip = $host_array[5];

my ($range) = $host_array[5] =~ /(\d{1,3})$/;

my ($network) = $host_array[5] =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3})/;

if ($range > 127) {

$ipdb{$name} = {ip => $ip,

network => $network,

subnet => 'hi',};

}else{

$ipdb{$name} = {ip => $ip,

network => $network,

subnet => 'low',};

}

}

foreach my $wkrst (keys %dhcp) {

if(($dhcp{$wrkst}-{network} eq $ipdb{$wkrst}->{network}) &&
($dhcp{$wrkst}->{subnet} eq $ipdb{$wkrst}->{subnet})) {

print "$wkrst is a match!\n"}

else {

print "in the dhcp lease file I found $wkrst with ip addr
$dhcp{$wkrst}->{ip} on subnet $dhcp{$wkrst}->{subnet} on network
$dhcp{$wkrst}->{network}\n";

print "in the ipdb I found $wkrst with ip addr
$ipdb{$wkrst}->{ip} on subnet $ipdb{$wrkst}->{subnet}\n";

}

}



The following is a sample of the the two data sources one is basically a
dhcp leases file and the other is the output from another script.



Dhcp leases example



# All times in this file are in UTC (GMT), not your local timezone. This
is

# not a bug, so please don't ask about it. There is no portable way to

# store leases in the local timezone, so please don't request this as a

# feature. If this is inconvenient or confusing to you, we sincerely

# apologize. Seriously, though - don't ask.

# The format of this file is documented in the dhcpd.leases(5) manual page.

# This lease file was written by isc-dhcp-V3.0pl2



lease 10.10.9.128 {

starts 3 2005/11/30 17:59:34;

ends 3 2005/11/30 21:59:34;

tstp 3 2005/11/30 21:59:34;

binding state free;

hardware ethernet 00:0b:97:2b:f0:4f;

uid "\001\000\013\227+\360O";

client-hostname "HOST1";

}

lease 10.10.12.12 2 {

starts 2 2005/12/20 16:10:51;

ends 2 2005/12/20 20:10:51;

tstp 2 2005/12/20 20:10:51;

binding state free;

hardware ethernet 00:0b:97:2b:ea:fe;

uid "\001\000\013\227+\352\376";

client-hostname "HOST2";

}

lease 10.10.97.170 {

starts 0 2005/12/25 23:08:02;

ends 1 2005/12/26 03:08:02;

tstp 1 2005/12/26 03:08:02;

binding state free;

hardware ethernet 00:0b:97:2b:ea:54;

uid "\001\000\013\227+\352T";

client-hostname "HOST3";

}



Script generated output



# Host info including names and ip addr

#

#



# HOSTNAME HOST IP

Host is HOST1 Subnet is 10.10.12.1

Host is HOST2 Subnet is 10.10.9.128

Host is HOST3 Subnet is 10.10.14.128



Thanks,



-angus







Relevant Pages

  • Re: how to get a networks IPs?
    ... >sniff a network without knowing with what IP to configure ... host routes, and have not one single pre-existing host on a ... the right subnet for the IP range that could be used... ... ping will be answered by every interface on the LAN that can ...
    (comp.os.linux.networking)
  • Re: TCP/IP question,PLEASE!
    ... mask is and how to apply it to IP address. ... a subnet is. ... For hosts to be in the same subnet, they must have the same network address. ... A host address's components: ...
    (microsoft.public.windowsxp.general)
  • Re: Netmasks for dummies
    ... 198.113.64.0-198.113.64.7 is a valid IP block for a /29 subnet. ... number of bits to the network and the remainder to the host. ... 1 is a network address and 1 is a broadcast address. ... address, .15 is the broadcast, .1-.14 are valid host addresses. ...
    (comp.os.linux.misc)
  • Re: NAT router confusion
    ... My understanding is that the netmask is only ... to determine how much of the IP address is used for the subnet address. ... last 8 bits of your IP is usable for a specific host on the ... network and the first 24 bits are used for the network address and subnet ...
    (freebsd-questions)
  • RE: routing tables on two NICs for network monitoring
    ... nothing will go beyond the 10.10.0.0/16 subnet. ... NEVER assign a host an IP address that's the ... I thought that I was specifying a network above, ... network routes persistent (ifdown/ifup/reboot all do not cause the routes to ...
    (Fedora)