我們需要在遠程主機的機制,可以拿起指定端口上的 請求的連接,並且還可以處理從命令行 可以使用的netcat,但是,以減少對外部程序的依賴調試器的交互,並給 你一個更好的主意,什麼是幕後發生的事情,你可以用同樣下面的程序
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use IO::Socket;
use Term::ReadLine;
use constant BIGNUM => 65536;
our $previous_input;
# Set host and port.
my $host = shift || 'localhost';
my $port = shift || 12345; # over 1024 please
die("Usage: $0 hostname portno") unless ($host =~ /\w+/ && $port =~
^\d+$/);
print "listening on $host:$port\n";
my $term = new Term::ReadLine 'local prompter';
my $OUT;
{
# strict subs complains about STDOUT, so turn it off for the moment.
no strict 'subs';
$OUT = $term->OUT || STDOUT;
}
$OUT->autoflush(1);
# Open the socket the debugger will connect to.
my $sock = new IO::Socket::INET(
LocalHost => $host,
LocalPort => $port,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
my $new_sock = $sock->accept();
# Try to pick up the remote hostname for the prompt.
my $remote_host = gethostbyaddr($sock->sockaddr(), AF_INET) || 'remote';
my $prompt = "($remote_host)> ";
my ($buf, $input
# Read output from the debugger, then read debugger input.
while (1) {
# Drop out if the remote debugger went away.
exit 0 unless sysread($new_sock, $buf, BIGNUM);
print $OUT $buf;
# Drop out if we got end-of-file locally (warning: this
# causes the remote Perl to drop dead because the socket goes away).
exit 0 unless defined($input = $term->readline($prompt));
print { $new_sock } munge_input($input);
# Add the line to the terminal history.
$term->addhistory($input) if $input =~ /\S/;
}
# The debugger interaction can get all confused if the string it gets
# passed is just a null. We clean this up here.
sub munge_input {
my $actual_input = shift;
$actual_input = "\n" unless defined $actual_input;
注意,無論程序選擇作爲 監聽器,你需要選擇一個端口號高超過1024,除非你運行的是 root (不是一個好主意)對machine.you可以從遠程計算機上使用PERLDB_OPTS
調試perl程序
PERLDB_OPTS="RemotePort=192.168.0.7:12345" perl helloworld
Hello World
process id(2798)
IP地址:端口號
在您標記此複本之前,我已經查看過 - http://stackoverflow.com/questions/29645053/trigger-perl-scripts-windows-remote,但這個不符合我的要求。 –
這與perl幾乎沒有任何關係,但可以簡化爲如何觸發在遠程系統上運行程序的問題。有很多顯而易見的方法,例如使用SSH登錄,在Web服務器等中使用CGI腳本,但您的真實需求未知。 –
Steffen - 我想觸發一個perl腳本,觸發另一個perl腳本,這是在遠程系統中自動完成FTP上傳/下載的操作。 –