View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Tom Scanlan > NetworkInfo-Discovery-0.12 > NetworkInfo::Discovery::Register



Annotate this POD


New  1
Open  0
View/Report Bugs


NetworkInfo::Discovery::Register - Register of network information


    use NetworkInfo::Discovery::Register;

    # is like doing a $r->autosave(1) and $r->file("/tmp/the.register")
    my $r = new NetworkInfo::Discovery::Register(autosave=>1, file=>"/tmp/the.register");

    $r->read_register();    # restore state from last save

    # ACLs allow us to remember only what we are allowed to
    $r->add_acl("allow", ""); # gets converted to 
    $r->add_acl("deny", "");

    my $interface = { ip    =>  '',
                      mac   =>  'aa:bb:cc:dd:ee:ff',
                      mask  =>  '',    # or 24 (as in prefix notation)
                      dns   =>  '',


    my $subnet  = { ip      =>  '', # this is the network address
                    mask    =>  24, # could also be ''


    my $gateway =   { ip    =>  '',
                      mask  =>  24,
                      mac   =>  'ff:ee:dd:cc:bb:aa',
                      dns   =>  '',


    $r->write_register();    # save state for future restore


NetworkInfo::Discovery::Register is a place to combine all that we have discovered about the network. As more information gets put in, the more corrolation we should see here.

For example, finding the netmask of an interface is not easy to do. If we happen to find a subnet from some source (say RIP, or an ICMP "Address Mask Request"), we may later see that those hosts with no netmask probably fit into the subnet. Once we are sure of this, we can add the netmask to the interfaces, and the interfaces into the subnet. By combining our knowledge in this manner, hopefully we discover more than we would by finding random bits of information.

The register stores information about interfaces, gateways, and subnets. Each is a list of hashes in it's core, and thus has an extensible set of attributes that we can tag onto each object. With that said, the pieces of information that I am using for corrolation is as follows (a * denotes that an attribute is mandatory):

        ip      # * this is the ip address of the interface
        mac     # * this is the ethernet MAC address of the interface
        mask    # the network mask in prefix or dotted-quad format 

        ip      # * an ip address on the subnet
        mask    # * the network mask in prefix or dotted-quad 

        ip      # * ip address of the interface that is this gateway

In this module we also provide for persistance using Storable. No one likes forgetting information, right?


add_interface ($interface_hashref)
add_interface_to_subnet ($interface_index, $subnet_index)
delete_interface ($interface_hashref)

This cuts an interface out of the interface list. To keep holes from forming in the list, take the last interface off the list and put it in place of the one we want to delete.

Also, keep track of pointers to subnets and gateways, from subnets and gateways, and interface lookup tables.

The special case is when we are the last interface in the list, and should just cut us out.

add_interface_to_gateway ($interface_index, $gateway_index)
remove_interface_from_gateway ($interface_index, $gateway_index)
remove_interface_from_subnet ($interface_index, $subnet_index)

internal only


internal only.


prints the formated register to STDOUT

read_register ([$filename])

tries to read the register from a file. if $filename is not give., tries to use what was set at creation of this object.

write_register ([$filename])

stores the register in $filename. if $filename is not given, tries to use what was set at creation of this object.

file ([ $filename ])

get/set the file to store data in


get/set auto save. pass this a "1" to turn on, a "0" to turn off. Autosave means that we will try to save the register to our "file" before we exit.

test_acl ($ip_to_test)

$ip_to_test is the ip addresse you want to check against the acl list set using add_acl. it should be in the form "a.b.c.d". we return as soon as we find a matching rule that says allow or deny. we return 1 to accept it, 0 to deny it.

acl_match ($ip_to_test, @against_these)

ip is like the acls are either in CIDR notation "" or a single address returns true if the ip matches the acl. returns false otherwise

add_acl ("(allow|deny)", @acls)

this function sets a list of hosts/networks that we are allowed to discover. note that order matters. the first argument is set to allow or deny. the meaning should be clear. @acls is a list of ip addresses in the form: a.b.c.d/mask # to acl a whole network or a.b.c.d # to acl a host

the following calls will allow us to discover stuff on only the network $d->add_acl("allow", ""); $d->add_acl("deny", "");

the following calls will allow us to discover anything but stuff on network $d->add_acl("deny", ""); $d->add_acl("allow", "");


this function clears the acl list

guess_mask ($ip)

attempt to guess the mask based on the ip. returns the guessed mask

add_event ("string")

add an event to the log


just tries to write_register if we have autosave turned on

syntax highlighting: