Home: Perl Programming Help: Beginner:
receiving free ip from giving subnet



zohman
Novice

Jun 6, 2017, 1:35 AM


Views: 2136
receiving free ip from giving subnet

i'm trying to solve some problem thinking how to start..

my task is to give as argument subnet ip in CIDR notation (for example: 192.168.1.0\24)
and hostname as FQDN format (for example: host01.domain.com)

and to get, first, 1 free ip from the subnet, meaning that it is not online/ping-able and not have any PTR record.
second, for the fqdn i want to make sure it is not registered in DNS.

is any one have some subroutine in-hand?


Code
my ($free_ip, $valid_fqdn) = query_ip_dns('192.168.1.0\24','host01.domain.com');


$free_ip should return free ip from within the given subnet range or return undef in case all hosts in subnet are in use.
$valid_fqdn can return true/false - registered in DNS already or not.

the idea is that if all checks will pass,
later on the script will register 'A record' in DNS with the provided FQDN and the retuerned IP.

Thanks in advance,
Zohman.


FishMonger
Veteran / Moderator

Jun 6, 2017, 8:38 AM


Views: 2130
Re: [zohman] receiving free ip from giving subnet

What have you tried?

Have you searched cpan for any related modules?

Here are some of the related modules you should look at.

Net::Netmask https://metacpan.org/pod/distribution/Net-Netmask/lib/Net/Netmask.pod
NetAddr::IP https://metacpan.org/pod/NetAddr::IP
Net::IP https://metacpan.org/pod/Net::IP#looping
Net::Ping https://metacpan.org/pod/Net::Ping
Net::DNS https://metacpan.org/pod/Net::DNS
Net::Nslookup https://metacpan.org/pod/Net::Nslookup