-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
147 changed files
with
4,960 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.