启用daytime服务 xinet.d udp fsockopen

5 篇文章 0 订阅

1. 安装xinetd

cat /etc/services | grep "daytime"
# for ubuntu
sudo apt-get install xinetd 

 如果是centos/red hat

sudo yum install xinetd.x86_64

centos默认普通用户不能用sudo: https://blog.csdn.net/fareast_mzh/article/details/81908198

2. 改配置文件

sudo emacs /etc/inetd.conf 

# /etc/inetd.conf:  see inetd(8) for further informations.
#
# Internet superserver configuration database
#
#
# Lines starting with "#:LABEL:" or "#<off>#" should not
# be changed unless you know what you are doing!
#
# If you want to disable an entry so it isn't touched during
# package updates just comment it out with a single '#' character.
#
# Packages should modify this file by using update-inetd(8)
#
# <service_name> <sock_type> <proto> <flags> <user> <server_path> <args>
#
#:INTERNAL: Internal services
#discard		stream	tcp	nowait	root	internal
#discard		dgram	udp	wait	root	internal
daytime		stream	tcp	nowait	root	internal
#time		stream	tcp	nowait	root	internal

#:STANDARD: These are standard services.

#:BSD: Shell, login, exec and talk are BSD protocols.

#:MAIL: Mail, news and uucp services.

#:INFO: Info services

#:BOOT: TFTP service is provided primarily for booting.  Most sites
#       run this only on machines acting as "boot servers."

#:RPC: RPC based services

#:HAM-RADIO: amateur-radio services

#:OTHER: Other services
#<off># bbs	stream	tcp	wait	root	/usr/sbin/ax25-node	ax25-node

去掉daytime开头的这行前面的#注释

sudo emacs /etc/xinetd.d/daytime

# default: off
# description: An internal xinetd service which gets the current system time
# then prints it out in a format like this: "Wed Nov 13 22:30:27 EST 2002".
# This is the tcp version.
service daytime
{
	disable		= no
	type		= INTERNAL
	id		= daytime-stream
	socket_type	= stream
	protocol	= tcp
	user		= root
	wait		= no
}

# This is the udp version.
service daytime
{
	disable		= no
	type		= INTERNAL
	id		= daytime-dgram
	socket_type	= dgram
	protocol	= udp
	user		= root
	wait		= yes
}

disable=yes改为disable=no

对于centos/red hat

修改 /etc/xinetd.d/daytime-stream和 /etc/xinetd.d/ daytime-dgram 中的disable为no;

 

3. 启动服务

 sudo /etc/init.d/xinetd restart

  centos:

sudo /bin/systemctl restart xinetd.service

 

4. 测试

nc localhost daytime

12 MAR 2019 01:09:55 UTC

 

5. udp.php

<?php
// Usage: php udp.php -h47.93.27.106 -p13

// @ref: http://php.net/manual/en/function.getopt.php
$options = getopt("h::p::");
$host = isset($options['h']) ? $options['h'] : '127.0.0.1';
$port = isset($options['p']) ? $options['p'] : 13;

$fp = fsockopen(sprintf("udp://%s", $host), $port, $errno, $errstr);
if (!$fp) {
    printf("ERROR: %d - %s\n", $errno, $errstr);
    exit($errno);
}

fwrite($fp, "\n");
echo fread($fp, 26);
fclose($fp);

$ php udp.php
12 MAR 2019 01:11:04 UTC

 

http://php.net/manual/en/function.fsockopen.php

http://php.net/manual/en/function.fread.php

http://php.net/manual/en/function.getopt.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fareast_mzh

打赏个金币

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值