linux command Line and shell script bible(笔记十八)
2013-09-21 08:03
435 查看
24.1.2 注意:可以直接从命令行控制任何类型的HTTP或HTML设置,如想使用HTTP
POST方法向web表单发送数据,只需将数据放在-post_data参数中;要将网站接受到的cookie储存在某个特定位置,可以使用-cookie_save_file参数
-dump抓取数据,结合sed,gawk命令
24.2
curl会将完整的web页面HTML代码返回到STDOUT上,可以用curl来批量下载文件,如果知道文件的下载地址,可以curl -s -o filename address
-s:选项让curl工作在安静模式,不会向STDOUT发送任何数据
-o:命令将输出重定向到一个文件名。(也就是下载的文件在哪)
结合at/cron命令就可一自动下载东西了。
24.3使用zsh处理网络
首先在shell中安装TCP模块:zmodload zsh/net/tcp
然后就可一使用ztcp命令了:ztcp [-acflLtv] [-d fd] [args]
-a:接受一个新链接
-c:关闭一个已有链接
-d:对链接使用指定的文件描述符
-f:强制关闭链接
-l:打开新的监听套接字
-L:列出当前已连接的套接字
-t:如果没有连接在等待,退出
-v:显示连接的详细信息
###############################server.sh#############################################
#!/bin/zsh
#zsh tcp server script
zmodload zsh/net/tcp
ztcp -l 5150 #监听
fd=$REPLY
echo "waiting fo a client..."
ztcp -a $fd #接受连接
clientfd=$REPLY
echo "client connected"
echo "welcom to my server" >& $clientfd
while [ 1 ]
do
read line <& $clientfd
if [[ $line = "exit" ]]
then
break
else
echo Recived:$line
echo OK >& $clientfd
fi
done
echo "client disconnected session"
ztcp -c $fd
ztcp -c $clientfdi
##################################client.sh##################################################
#!/bin/zsh
#zsh tcp client program
zmodload zsh/net/tcp
ztcp localhost 5150 #发送请求
hostfd=$REPLY
read line <& $hostfd
echo $line
while [ 1 ]
do
echo -n "Enter text:"
read phrase
echo Sending $phrase to remote host...
echo $phrase >& $hostfd
if [[ $phrase = "exit" ]]
then
break
fi
read line <& $hostfd
echo "Received: $line"
done
ztcp -c $hostfd
###########################################################################################
注意:可以在网络中的两个不同的Linux系统上或统一个系统中的两个不同终端会话中运行这两个程序。
先运行服务器程序用于监听,然后启动客户端程序用于发送链接请求
POST方法向web表单发送数据,只需将数据放在-post_data参数中;要将网站接受到的cookie储存在某个特定位置,可以使用-cookie_save_file参数
-dump抓取数据,结合sed,gawk命令
24.2
curl会将完整的web页面HTML代码返回到STDOUT上,可以用curl来批量下载文件,如果知道文件的下载地址,可以curl -s -o filename address
-s:选项让curl工作在安静模式,不会向STDOUT发送任何数据
-o:命令将输出重定向到一个文件名。(也就是下载的文件在哪)
结合at/cron命令就可一自动下载东西了。
24.3使用zsh处理网络
首先在shell中安装TCP模块:zmodload zsh/net/tcp
然后就可一使用ztcp命令了:ztcp [-acflLtv] [-d fd] [args]
-a:接受一个新链接
-c:关闭一个已有链接
-d:对链接使用指定的文件描述符
-f:强制关闭链接
-l:打开新的监听套接字
-L:列出当前已连接的套接字
-t:如果没有连接在等待,退出
-v:显示连接的详细信息
###############################server.sh#############################################
#!/bin/zsh
#zsh tcp server script
zmodload zsh/net/tcp
ztcp -l 5150 #监听
fd=$REPLY
echo "waiting fo a client..."
ztcp -a $fd #接受连接
clientfd=$REPLY
echo "client connected"
echo "welcom to my server" >& $clientfd
while [ 1 ]
do
read line <& $clientfd
if [[ $line = "exit" ]]
then
break
else
echo Recived:$line
echo OK >& $clientfd
fi
done
echo "client disconnected session"
ztcp -c $fd
ztcp -c $clientfdi
##################################client.sh##################################################
#!/bin/zsh
#zsh tcp client program
zmodload zsh/net/tcp
ztcp localhost 5150 #发送请求
hostfd=$REPLY
read line <& $hostfd
echo $line
while [ 1 ]
do
echo -n "Enter text:"
read phrase
echo Sending $phrase to remote host...
echo $phrase >& $hostfd
if [[ $phrase = "exit" ]]
then
break
fi
read line <& $hostfd
echo "Received: $line"
done
ztcp -c $hostfd
###########################################################################################
注意:可以在网络中的两个不同的Linux系统上或统一个系统中的两个不同终端会话中运行这两个程序。
先运行服务器程序用于监听,然后启动客户端程序用于发送链接请求
相关文章推荐
- linux command Line and shell script bible(笔记十三)
- linux command Line and shell script bible(笔记二)
- linux command Line and shell script bible(笔记一)
- linux command Line and shell script bible(笔记二_非用户变量)
- linux command Line and shell script bible(笔记六_比较)
- linux command Line and shell script bible(笔记十四)
- linux command Line and shell script bible(笔记十六)
- linux command Line and shell script bible(笔记七)
- linux command Line and shell script bible(笔记五)
- linux command Line and shell script bible(笔记八)
- linux command Line and shell script bible(笔记十一)
- linux command Line and shell script bible(笔记三_权限/用户)
- linux command Line and shell script bible(笔记九)
- linux command Line and shell script bible(笔记十)
- linux command Line and shell script bible(笔记十九)
- linux command Line and shell script bible(笔记十五)
- linux command Line and shell script bible(笔记十二)
- linux command Line and shell script bible(笔记一_文档/文件系统)
- linux command Line and shell script bible(笔记四)
- linux command Line and shell script bible(笔记三)