有人telnet我的服务器时运行脚本

时间:2015-02-19 22:50:51

标签: bash shell telnet

  

我有:

1)DigitalOcean上的Droplet ubuntu / debian / fedora

2)简单的脚本回应“script.sh”

  

我想:

当某人从终端telnet我的服务器时:telnet MY_DROPLET_IP使我的script.sh在他的终端中执行并在此之后退出。

总结一下,我需要这样的东西(看看这个):telnet towel.blinkenlights.nl

2 个答案:

答案 0 :(得分:1)

由于telnet不需要握手,因此可以在连接到端口23时set up xinetd to run the script

答案 1 :(得分:0)

安装:

sudo apt-get install xinetd telnetd

/etc/xinetd.d/telnet文件内容:

service login
{
    port            = 23 
    socket_type     = stream
    protocol        = tcp
    wait            = no
    user            = root
    server          = /usr/bin/script.sh       
    server_args     = test
}

/etc/xinetd.conf内容:

{
# Please note that you need a log_type line to be able to use log_on_success
# and log_on_failure. The default is the following :
# log_type = SYSLOG daemon info
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30
}

includedir /etc/xinetd.d

/etc/inetd.conf内容:

telnet      stream  tcp nowait telnetd  /usr/bin/script.sh

重新启动xinetd:

/etc/init.d/xinetd restart

编辑: 别忘了

chmod +x /usr/bin/script.sh