Using serial communication, use the following script at the standby to detect heartbeat signal from the host, once the number of not accepted more than the specified number, the standby machine think the host down machine, automatically set as the host network parameters, replace the host to provide services.
# !
perl-w use strict;
Use Win32:: SerialPort; My $port = ' COM2 '; # Serail Port name registried in OS my $count = 0; # count Number of heartbeat-receiving failture my $max _count = 5; # Max Fail Count to is tolerated my $interface = ' #----------------------------------# interface IP configuration #------- ---------------------------pushd Interface IP # ' local ' interface IP configuration set address name= ' local ' source=static addr=192.168 .6.185 mask=255.255.255.0 Set address name= ' local ' gateway=192.168.6.65 gwmetric=0 set DNS name= ' local ' source=static add r=192.168.6.112 register=primary Add DNS name= "local" addr=192.168.6.201 index=2 set wins name= "local" source=static addr =none POPD # interface IP configuration end '; # Net Inetrface Config information sub ErrLog {# Log the Failtrue occuring time Open ERR, ' >>err.
Log ';
My @time = LocalTime (); My $time = sprintf ("%d", $time [5] + 1900). ' - '
. sprintf ("%d", $time [4] + 1). ' - '
. "$time [3]". ' '
. sprintf ("%.2d", $time [2]). ' : '
. sprintf ("%.2d", $time [1]). ' : '
.
sprintf ("%.2d", $time [0]); Print ERR $time.
"\ n";
Close ERR;
Sub Ipchange {# change IP addrress open TMP, ' >tmp ';
Print TMP $interface;
Close TMP;
eval {System ' netsh-f tmp ';
Unlink ' tmp ';
};
if ($@) {return 0;}
return 1;
My $ob = Win32:: SerialPort-> New ($port) or die "Cannot OPEN $port";
# Open serial Port eval {# Set serial port Properties $ob-> baudrate (9600);
$ob-> parity (' none ');
$ob-> databits (8);
$ob-> stopbits (1);
$ob-> handshake (' none ');
};
if ($@) {die ' SET FAILED ';}
$ob-> write_settings or die "Cannot write $port DRIVER";# Write to port driver to make it active while (1) {# Loop receiving Heartbeat ' Remote machine # change IP
Address after designated Count of Failture me ($length, $result) = $ob-> read (10);
if ($result) {$count = 0;
} elsif ($count = = $max _count) {errlog ();
if (not Ipchange ()) {print ' IP change FAILED ';}
Last;
else {$count + +;
Sleep (1);
} undef $ob;