shell脚本实现tcp-udp协议通讯

shell脚本实现tcp-udp协议通讯

ID:16799740

大小:21.03 KB

页数:6页

时间:2018-08-24

shell脚本实现tcp-udp协议通讯_第1页
shell脚本实现tcp-udp协议通讯_第2页
shell脚本实现tcp-udp协议通讯_第3页
shell脚本实现tcp-udp协议通讯_第4页
shell脚本实现tcp-udp协议通讯_第5页
资源描述:

《shell脚本实现tcp-udp协议通讯》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、linuxshell脚本实现tcp/upd协议通讯(重定向应用)前几天发了重定向以及管道相关使用方法,今天这里发些很有趣的例子。通过重定向实现基于tcp/udp协议的软件通讯。 linux设备里面有个比较特殊的文件:/dev/[tcp

2、upd]/host/port只要读取或者写入这个文件,相当于系统会尝试连接:host这台机器,对应port端口。如果主机以及端口存在,就建立一个socket连接。将在,/proc/self/fd目录下面,有对应的文件出现。一、测试下:/dev/tcp/host/post文件123456789101

3、112131415161718192021222324252627[chengmo@centos5 shell]$ cat

4、linuxshell脚本实现tcp/upd协议通讯(重定向应用) [chengmo@centos5 shell]$ exec 8<>/dev/tcp/127.0.0.1/22[chengmo@centos5 shell]$ ls -l /proc/self/fd/总计0lrwx------1chengmochengmo6410-2123:050-> /dev/pts/0lrwx------1chengmochengmo6410-2123:051-> /dev/pts/0lrwx------1chengmochengmo6410-

5、2123:052-> /dev/pts/0lr-x------1chengmochengmo6410-2123:053-> /proc/22185/fdlrwx------1chengmochengmo6410-2123:058->socket:[15067661] #文件描述符8,已经打开一个socket通讯通道,这个是一个可以读写socket通道,因为用:"<>"打开[chengmo@centos5 shell]$ exec 8>&-#关闭通道[chengmo@centos5 shell]$ ls -l /proc/self

6、/fd/总计0lrwx------1chengmochengmo6410-2123:080-> /dev/pts/0lrwx------1chengmochengmo6410-2123:081-> /dev/pts/0lrwx------1chengmochengmo6410-2123:082-> /dev/pts/0lr-x------1chengmochengmo6410-2123:083-> /proc/22234/fd 从时间服务器读取时间:[chengmo@centos5html]$cat

7、b.nist.gov/135549110-10-2211:33:491700596.3UTC(NIST)*otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommit

8、teeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand上面这条语句使用重定向输入语句就可以了。 二、通过重定向读取远程web服务器头

9、信息12345678910111213141516171819202122232425262728293031#!/bin/sh#testhttphead.sh#实现通过主机名,端口读取web服务器header信息#copyrightchengmo,qq:829

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。