From 1f346fd6b56669c3fe3be383f5e543cc514cc5db Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 29 Jul 2009 13:03:39 +0000 Subject: [PATCH] check if IP is available using Net::Ping --- bin/dhcpd.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/dhcpd.pl b/bin/dhcpd.pl index 2f62670..059f9f7 100755 --- a/bin/dhcpd.pl +++ b/bin/dhcpd.pl @@ -10,6 +10,7 @@ use autodie; use IO::Socket::INET; use File::Slurp; use Data::Dump qw/dump/; +use Net::Ping; use lib 'lib'; use Net::DHCP::Packet; @@ -60,10 +61,12 @@ sub client_ip { mkdir $_ foreach grep { ! -e $_ } map { "$conf/$_" } ( 'ip', 'mac' ); + my $p = Net::Ping->new; + my $prefix = $server_ip; $prefix =~ s{\.\d+$}{.}; my $ip = $prefix . $addr; - while ( -e "conf/ip/$ip" ) { + while ( -e "conf/ip/$ip" || $p->ping( $ip ) ) { $ip = $prefix . $addr++; die "all addresses allocated!" if $addr == $ip_to; } -- 2.20.1