use IO::Socket; #============Main=============== my $sock; $sock=login_router(); print $sock; exit; #============End=============== sub login_router { my $socket; $socket = new IO::Socket::INET (PeerAddr => "192.168.1.240", PeerPort => "23" , Proto => 'tcp') ; if ($socket) { print "Connection is established\n"; } else { die "Error: $!"; } sleep(4); $socket->autoflush(); my $input = ""; my $char = ""; until ($input =~ /Login :/){ $socket->sysread($char, 1); $input .= $char; } print $input; # Write the login name syswrite $socket, "ecidslam\r\n"; sleep(2); # Wait for the Password prompt my $input = ""; my $char = ""; until ($input =~ /Password :/){ $socket->sysread($char, 1); $input .= $char; } print $input; syswrite $socket, "Hi-FOCuS\r\n"; # To read the output from the socket while(<$socket>) { last if (/welcome/); die "Exit... Login error\n" if (/Permission Denied/); # Print each line read from socket print $_; } return $socket; }