博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
websockets handshake using netcat/bash script
阅读量:4685 次
发布时间:2019-06-09

本文共 1240 字,大约阅读时间需要 4 分钟。

 

During the process of learning websockets, wanted to try out the handshake mechanism using a simple server cooked using netcat/bash script. The script just reads the request message, parses the key, forms the SHA1/base64 response key and sends the response.

Tested it with chromium. Attached are the code and screenshot.

#!/bin/bashrm -rf twhile truedo   read packet   echo $packet >> t   cnt=`echo $packet | wc -c`   if [ $cnt == 2 ] #end of message   then      key=`cat t | grep "Sec-WebSocket-Key:" | cut -f2 -d " "`      keylen=`echo -n $key | wc -c`      keylen=`expr $keylen - 1`      key2=`echo -n $key | cut -c -$keylen`      magic="258EAFA5-E914-47DA-95CA-C5AB0DC85B11"      resp=`echo -n $key2$magic | openssl sha1 -binary | base64`      echo   -n "HTTP/1.1 101 Switching Protocols"$'\r\n'      echo   -n "Connection: Upgrade"$'\r\n'      echo   -n "Upgrade: websocket"$'\r\n'      echo   -n "Sec-WebSocket-Accept: $resp"$'\r\n\r\n'      break   fidone

HTML with websocket call

nvoke netcat as follows and open the above HTML using chromium/firefox

nc -l -p 8888 -e ./wshandshake.sh 
Screenshot of Chromium websocket developer console, post invocation.

 

Copy from 

转载于:https://www.cnblogs.com/sunsweet/archive/2013/06/01/3111957.html

你可能感兴趣的文章
altium annotate 选项设置 complete existing packages
查看>>
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
DRF的分页
查看>>
html td 限制 高度 和 宽度
查看>>
mysql查询一个表的字段,添加或修改到另外一个表的数据
查看>>
CL.exe的 /D 选项, Preprocessor Macro预处理器宏定义
查看>>
[Pytorch]Pytorch中tensor常用语法
查看>>
ZOJ 1008 Gnome Tetravex
查看>>
Jenkin远程部署Tomcat8.5总结
查看>>
编写Linux中sh文件执行时出现莫名字符的问题
查看>>
简单数论(一)
查看>>
CXF和Axis的比较【转】
查看>>
设计一个函数,它接受不定数量的参数,这是参数都是函数。这些函数都接受一个回调函数作为参数,按照回调函数被调用的顺序返回函数名...
查看>>
MyBatis学习总结_06_调用存储过程
查看>>
SEO知识图一
查看>>
[开源JVM] yvm - 自制Java虚拟机
查看>>
Open vSwitch安装
查看>>
【Android】 No Activity found to handle Intent.
查看>>