Yesterday I discovered the xinetd; an internet services daemon. I immediately liked the idea of writing simple services that work on stdin and stdout but that can be accessed over the internet via sockets. So, I set out to write a simple Python server that can be integrated with xinetd. Here is the server:
#!/usr/bin/python
import sys
request = ''
while True:
data = sys.stdin.readline().strip()
request = request + data + '<br>'
if data == "":
print 'HTTP/1.0 200 OK'
print ''
print '<html><body><p>'+request+'</p></body></html>'
sys.stdout.flush()
break;
I am assuming that a web browser will connect to my server, the server will then 'echo' the request back to the browser allowing the browser to display the request. As you can see the input is received via stdin and output is returned via stdout.
If xinetd is not already installed then you will obviously have to install it first. Since I am doing this on Ubuntu the following works for me:
sudo apt-get install xinetd
After installing xinetd you need to create a config file for the service. I called my service http_echo and my config file (located in /etc/xinetd.d) is named similarly; http_echo. My configuration file looks like this:
service http_echo
{
protocol = tcp
disable = no
port = 9991
flags = REUSE
socket_type = stream
wait = no
user = johan
server = /home/johan/code/http_echo/http_echo
log_on_failure += USERID
}
Most of this file is quite self explanatory. Please refer to the xinetd documentation for more information.The port property should make the service run on the specified port without having to add an entry in the services file (/etc/services) . I have had to add an entry in my services file to make this setup work:
http_echo 9991/tcp
Then simply restart the xinetd service:
sudo /etc/init.d/xinetd restart
Pointing a browser to the server on the specified port (9991), will yield the pleasing results below:
GET / HTTP/1.1
Host: localhost:9991
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.33 Safari/532.0
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
And that is how simple it is to write a service in Python that runs under xinetd.
分享到:
相关推荐
包含 tftp-server-0.42-3.1.i386.rpm xinetd-2.3.14-18.fc9.i386.rpm tftp-0.42-3.1.i386.rpm
xinetd-2.3.14-40.el6.x86_64,xinetd即extended internet daemon,xinetd是新一代的网络守护进程服务程序,又叫超级Internet服务器。经常用来管理多种轻量级Internet服务。xinetd提供类似于inetd+tcp_wrapper的功能...
Xinetd:即extended internet daemon,是新一代的网络守护进程服务程序,又叫超级Internet服务器,常用来管理多种轻量级Internet服务。
xinetd-2.3.14-13.el5.x86_64xinetd-2.3.14-13.el5.x86_64xinetd-2.3.14-13.el5.x86_64xinetd-2.3.14-13.el5.x86_64xinetd-2.3.14-13.el5.x86_64xinetd-2.3.14-13.el5.x86_64xinetd-2.3.14-13.el5.x86_64
linux系统使用telnet命令需要安装的三个包,可以百度一下怎么安装。一共三个,然后去修改telnet配置文件disable=no,重启xinted服务即可使用telnet命令
超级服务xinetd最新源码下载。 xinetd提供类似于inetd+tcp_wrapper的功能,但是更加强大和安全。它能提供以下特色: * 支持对tcp、udp、RPC服务(但是当前对RPC的支持不够稳定) * 基于时间段的访问控制 * 功能...
xinetd rpm文件,用来配合haproxy,通过xinetd提供的http服务mycatstatus来让Haproxy进行Mycat服务检测,即检测Mycat存活状态。Haproxy通过调用该http服务获取Mycat运行状态。
平时vnc server进程并不运行,当有客户端连接时会自动开启进程。 使用51024端口可以运行1024*768的分辨率,使用50800可以运行800*600的分辨率。 vnc连接后会先出现Linux的登陆画面,输入用户名和密码后进入相应的...
linux telnet服务守护进程,在命令行下执行 rpm -ivh xinetd*.rpm 进行安装,安装完后,编辑 /etc/xinetd.d/telnet,把disable 的yes 改为no 。执行命令 service xinetd start 即可启动服务,必要时关闭防火墙
xinetd,telnet-server守护进程,
xinetd,telnet-server守护进程,需安装相关包能够安装telnet-server包,记录一下,主要是便于下载方便。
xinetd安装程序,xinetd 取代了inetd,并且提供了访问控制、加强的日志和资源管理功能
简析Suse Linux的xinetd服务.pdf
用xinetd简化Linux与Windows的通讯.pdf
xinetd - A secure replacement for inetd. Distribution: CentOS 5 Repository: CentOS x86_64 Package name: xinetd Package version: 2.3.14 Package architecture: x86_64 Package type: rpm Installed ...
xinetd是一个daemon程序,所有结尾带d的程序都是daemon程序,也就是守护程序 守护程序分为2种处理模式: 第一个是stand alone状态的,表示该程序始终监听,一直处于运行状态,例如httpd 第二个是super daemon,它...
telnet离线安装包rpm(含xinetd),适用于centOS6版本!
xinetd-2.3.15-14.el7.x86_64.rpm
在命令行下执行 rpm -ivh xinetd*.rpm 进行安装,安装完后,编辑 /etc/xinetd.d/telnet,把disable 的yes 改为no 。执行命令 service xinetd start 即可启动服务,必要时关闭防火墙