Example programs

Not applicable
Posts: 1
1967     0


I am trying to find a simple program that will give me a hostname to ip mapping. 
I tried reading the api/doc but I am left with more answers than questions after reading that. 
I create a new session
my $session = Infoblox:Smiley Frustratedession->new (
                "master"=> “xxxx",
                "username" => "$username",
                "password" => "$password",
    @result_array = $session->get( object => "Infoblox:Smiley Very HappyNS::Host",
                                   name   => “”);
   $object = $result_array[0];;
foreach my $hostname (%$object) {
    print "key <<<$hostname>>\n";
    print "value<", $host->{$hostname}, ">\n";
I notice that ipv4addrs is blank (but I can see Ip address on web ui)
I noticed this program in one of the sites
     my @result_array = $session->search(
            "object" => "Infoblox:Smiley Very HappyNS::Record::A",
            "name" => “" );
     my $obj;
     foreach my $match (@result_array)
        if( $match->name() eq “" )
           print "Matches\n";
           print $match->ipv4addr() , "\n";
           $obj = $match;
But i never ever get a return address?
Where can I find code that will print the ip address corresponding to a hostname? 
I can use Unix tools to extract that, but would like to query Infoblox to get that data.

Have you tried to see what

Posts: 39
1968     0

Have you tried to see what output you get by doing a print dumper($hostname)?

Do mind that the Infoblox:Smiley Very HappyNS::Host doesn't have a method called ipv4addr() but a method called ipv4addrs() which is an array of IP values and/or fixed address objects.

I once created a script to find all printers that were defined in Infoblox. As some printers have static IPs and some have a fixed DHCP address I needed to make sure in my script that the right value was retrieved. As I know that the printers only have 1 IP I also only took the first object/value in the area.

Here's my code snippet :

    foreach (@result_array)
        my $ipaddr;
        $ipaddr = $_->ipv4addrs->[0] if(!ref($_->ipv4addrs()->[0]));  #contains value and not a reference
        $ipaddr = $_->ipv4addrs->[0]->ipv4addr() if(ref($_->ipv4addrs()->[0]));    #contains reference to fixedaddress
        print $_->name() & "\t" & $ipaddr & "\n";
I hope this can help.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You