Skip to content

Commit

Permalink
新增代码并编辑 README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
asyncins committed Jun 26, 2019
1 parent 27c2743 commit 94b5301
Show file tree
Hide file tree
Showing 147 changed files with 4,960 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .idea/antispider.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

961 changes: 961 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Empty file added 02/2-3/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions 02/2-3/websocket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio
import logging
from datetime import datetime
from aiowebsocket.converses import AioWebSocket

async def startup(uri):
async with AioWebSocket(uri) as aws:
# 初始化 aiowebsocket 库的连接类
converse = aws.manipulator
# 设定需要向服务器发送的信息
message = b'AioWebSocket - Async WebSocket Client'
while True:
# 不断的向服务器发送信息,并打印输出信息发送内容和时间
await converse.send(message)
print('{time}-Client send: {message}'
.format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), message=message))
# 不断的读取服务器推送给客户端的信息,并打印输出信息内容和时间
mes = await converse.receive()
print('{time}-Client receive: {rec}'
.format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))


if __name__ == '__main__':
# 设定远程服务器地址
remote = 'wss://echo.websocket.org'
try:
# 开启事件循环,调用并指定的方法
asyncio.get_event_loop().run_until_complete(startup(remote))
except KeyboardInterrupt as exc:
logging.info('Quit.')
17 changes: 17 additions & 0 deletions 04/4-1/4-1-1-one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests
from parsel import Selector


url = 'http://www.porters.vip/verify/uas/index.html'
# 向目标网址发起网络请求
resp = requests.get(url)
# 打印输出状态码
print(resp.status_code)
# 如果本次请求的状态码为200则继续,否则提示失败
if resp.status_code == 200:
sel = Selector(resp.text)
# 根据HTML标签和属性从响应正文中提取新闻标题
res = sel.css('.list-group-item::text').extract()
print(res)
else:
print('This request is fial.')
17 changes: 17 additions & 0 deletions 04/4-1/4-1-1-two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests
from parsel import Selector
# 使用Postman的身份标识
header = {"User-Agent": "Postman"}
url = 'http://www.porters.vip/verify/uas/index.html'
# 向目标网址发起网络请求,但将客户端身份标识切换为Postman
resp = requests.get(url, headers=header)
# 打印输出状态码
print(resp.status_code)
# 如果本次请求的状态码为200则继续,否则提示失败
if resp.status_code == 200:
sel = Selector(resp.text)
# 根据HTML标签和属性从响应正文中提取新闻标题
res = sel.css('.list-group-item::text').extract()
print(res)
else:
print('This request is fial.')
Empty file added 04/4-1/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions 04/4-2/4-2-1-one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests
from lxml import etree

url = 'http://www.porters.vip/verify/cookie/content.html'
# 向目标网址发起网络请求
resp = requests.get(url)
# 打印输出状态码
print(resp.status_code)
# 如果本次请求的状态码为200则继续,否则提示失败
if resp.status_code == 200:
# 将响应正文赋值给html变量
html = etree.HTML(resp.text)
# 根据HTML标签和样式属性从文本中标题的Element对象
res = html.cssselect('.page-header h1')
print(res)
else:
print('This request is fial.')
18 changes: 18 additions & 0 deletions 04/4-2/4-2-1-two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import requests
from lxml import etree

url = 'http://www.porters.vip/verify/cookie/content.html'
# 向目标网址发起网络请求
header = {"Cookie": "isfirst=789kq7uc1pp4c"}
resp = requests.get(url, headers=header)
# 打印输出状态码
print(resp.status_code)
# 如果本次请求的状态码为200则继续,否则提示失败
if resp.status_code == 200:
# 将响应正文赋值给html变量
html = etree.HTML(resp.text)
# 根据HTML标签和样式属性从文本中标题的Element对象
res = html.cssselect('.page-header h1')[0].text
print(res)
else:
print('This request is fial.')
Empty file added 04/4-2/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions 04/4-2/fet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function randcookie(){
// 生成随机字符串用作cookie值
var header = randints(9, 3, 0);
var middle = randstrs(5);
var footer = randints(9, 6, 0);
var pp = randstrs(3);
var res = header + middle + footer + pp
return res;
}

function randints(r, n, tof){
/* 生成随机数字,tof决定返回number类型或者字符串类型
r 代表数字范围 n 代表数量
*/

var result = [];
if(tof){
return Math.floor(Math.random()*r);
}
for(var i=0;i<n;i++){
s = Math.floor(Math.random()*r);
result.push(s);
}
return result.join('');
}

function randstrs(n){
// 生成随机字母,n为随机字母的数量
var result = [];
for(var i=0; i<n; i++){
s = String.fromCharCode(65+randints(25, 1, 1));
result.push(s);
}
return result.join('');
}

// 设置Cookie
document.cookie = 'auth=' + randcookie();
// 跳转到指定页面
location.href = '/index.html';
32 changes: 32 additions & 0 deletions 04/4-3/4-3-1-one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from time import time
from random import randint, sample
import hashlib


def hex5(value):
# 使用 md5 加密值并返回加密后的字符串
manipulator = hashlib.md5()
manipulator.update(value.encode('utf-8'))
return manipulator.hexdigest()


# 生成1-9之间的5个随机数字
action = "".join([str(randint(1, 9)) for _ in range(5)])
# 生成当前时间戳
tim = round(time())
# 生成5个随机大写字母
randstr = "".join(sample([chr(_) for _ in range(65, 91)], 5))
# 三个参数拼接后进行md5加密
value = action+str(tim)+randstr
hexs = hex5(value)
print(action, tim, randstr, hexs)


import requests
def uri():
args = '?actions={}&tim={}&randstr={}&sign={}'.format(action, tim, randstr, hexs)
return args

url = 'http://www.porters.vip/verify/sign/fet' + uri()
resp = requests.get(url)
print(resp.status_code, resp.text)
83 changes: 83 additions & 0 deletions 04/4-3/4-3-2/4-3-2-one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import tornado.ioloop
import tornado.web
import hashlib
import os
from datetime import datetime
from time import time


class MainHandler(tornado.web.RequestHandler):
def get(self):
# 返回页面的视图
self.render("index.html")

class FetHandler(tornado.web.RequestHandler):
# 定义返回内容
content = """
<p>参团的游客,应听从领队、导游人员的安全提醒,切莫擅自行动。
自身的人身、财物安全要注意,购买人身意外险,贵重物品要随身携带,
不要留在车内或者交由他人保管。参加漂流、摩天轮等高风险项目的时候,
要认真听从工作人员的安排,切莫求刺激而发生意外。</p>
<p >以下是本次参团出行需要遵守的规范要求:</p>
<p>一、跟刺激相比,命更重要,没有命就什么都没了。</p>
<p>二、旅行中会遇到很多你从未见过的植物和动物,不要轻易打扰它们,有可能有毒。</p>
<p>三、身体感觉不适,尤其是发烧、乏力和呕吐等情况必须报告随队医护人员。</p>
<p>四、出发前请跟家人沟通好,避免造成失联错觉。</p>
<p>五、出发前请按照队长的要求准备好必备衣物和干粮,最重要的是水。</p>
<p>六、旅行途中必须紧跟队伍,不许在无人知晓的情况下行动。</p>
<p>七、如不慎走失,请先释放信号弹,半小时后无人联系再想办法报警。</p>
<p>八、如果不同意以上几条,请在出发前告知队长。</p>
<p>九、最重要的是:没有命,就什么都没了。</p>
"""
@staticmethod
def deltas(tp):
# 将前端传递的时间戳与当前时间戳对比并返回差值秒数
tamp = int(tp)
now = round(time())
delta = datetime.fromtimestamp(now) - datetime.fromtimestamp(tamp)
return delta.total_seconds()

@staticmethod
def hex5(value):
# 使用 md5 加密值并返回加密后的字符串
manipulator = hashlib.md5()
manipulator.update(value.encode('utf-8'))
return manipulator.hexdigest()

def comparison(self, actions, tim, randstr, sign):
# 根据传递的参数计算md5值,并与客户端提交的md5值进行比对
value = actions+tim+randstr
hexs = self.hex5(value)
if sign == hexs:
return True
return False

def get(self):
# 返回数据的视图
params = self.request.arguments # 获取请求正文
actions = params.get('actions')[0].decode('utf-8')
tim = params.get('tim')[0].decode('utf-8')
randstr = params.get('randstr')[0].decode('utf-8')
sign = params.get('sign')[0].decode('utf-8')
seconds = self.deltas(tim) # 取双端时间差值
if self.comparison(actions, tim, randstr, sign) and seconds < 5:
# 如果双端 MD5 值和时间戳差值都符合要求则返回正常内容
self.write(self.content)
else:
self.set_status(403)


def make_app():
# 路由和静态文件路径设置
return tornado.web.Application(
[(r"/", MainHandler), (r"/fet", FetHandler)],
template_path=os.path.join(os.path.dirname(__file__), 'template'),
static_path=os.path.join(os.path.dirname(__file__), 'static')
)


if __name__ == "__main__":
# 绑定端口并启动
app = make_app()
app.listen(8206)
tornado.ioloop.IOLoop.current().start()
Empty file added 04/4-3/4-3-2/__init__.py
Empty file.
Loading

0 comments on commit 94b5301

Please sign in to comment.