Код:
sub hw_connect
{
my($md5);
my(@cmd,@reply,%attr);
$HW_error='';
$sock='';
&hw_debug('start connecting to the mikrotik');
$sock=new IO::Socket::INET(PeerAddr=>$HW_nas_ip, PeerPort=>$HW_nas_port, Proto=>'tcp', Timeout=>$HW_nas_connect_t_out);
if( !$sock )
{
$HW_error=$!;
return 0;
}
$sock->blocking(0);
@cmd=('/login');
&hw_dialog($sock,\@cmd,\@reply,\%attr);
exists $attr{ret} or return 0;
$md5=new Digest::MD5;
$md5->add(chr(0));
$md5->add($HW_nas_pass);
$md5->add(pack("H*",$attr{ret}));
@cmd=('/login','=name='.$HW_nas_user,'=password='.$HW_nas_pass);
&hw_dialog($sock,\@cmd,\@reply,\%attr) or return 0;
return ($reply[0] eq '!done');
}