Skip to content

Commit

Permalink
Added proxy mode, change README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerfalling committed Mar 27, 2023
1 parent 6e3a433 commit fedd7a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@
## 使用方法

```shell
python main.py --cookie[ --epochs[ --tasks-num[ --requests-num[ --wait[ --wait-epoch[ --print]]]]]]
python main.py --cookie[ --epochs[ --tasks-num[ --requests-num[ --wait[ --wait-epoch[ --out[ --proxy]]]]]]]
```
```shell
python rank.py --cookie
python rank.py --cookie[ --once]
```
## 参数
main.py
* `-c` `--cookie` cookie
* `-e` `--epochs` 重复次数
* `-tn` `--tasks-num` task数量
* `-rn` `--requests-num` 单个task循环请求次数,最好不要超过1000
* `-w` `--wait` 单个task中每次请求后等待时间(s)
* `-we` `--wait-epoch` 每次循环后等待时间(s)
* `-p` `--print` 是否打印报文(y/n)
* `-o` `--out` 是否打印报文(y/n)
* `-p` `--proxy` 设置代理,格式为"ip:port"
rank.py
- `-c` `--cookie` cookie,同main.py
- `-o` `--once` 只获取一次排名(y/n)
## 如何获取cookie
Expand All @@ -40,7 +48,7 @@ python rank.py --cookie
理论次数 = tn * rn * epochs
理论耗时 = (rm * w * n + we) * epochs
理论耗时 = (rm * w * n + we) * epochs - we
*n为正整数,一般为1,除非执行tn次发送报文的时间大于wait时间,n为发送tn次报文所需时间除以wait时间向上取整*
Expand Down Expand Up @@ -104,7 +112,9 @@ python rank.py --cookie
## 推荐参数
运行一次理论次数200,000次,理论时间490s
```shell
python main.py -c xxxxxxxxx -e 4 -tn 50 -rn 1000 -w 0.1 -we 30 -p n
python main.py -c xxxxxxxxx -e 4 -tn 50 -rn 1000 -w 0.1 -we 30
```
28 changes: 26 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import socket
import time
import argparse
import socks

nots = 0

Expand All @@ -19,7 +20,8 @@ def get_args():
parser.add_argument('-rn', '--requests-num', type=int, default=1, help='单个task循环请求次数,最好不要超过1000')
parser.add_argument('-w', '--wait', type=float, default=0.1, help='单个task中每次请求后等待时间(s)')
parser.add_argument('-we', '--wait-epoch', type=float, default=30, help='每次循环后等待时间(s)')
parser.add_argument('-p', '--print', type=str, default='n', help='是否打印报文(y/n)')
parser.add_argument('-o', '--out', type=str, default='n', help='是否打印报文(y/n)')
parser.add_argument('-p', '--proxy', type=str, default=None, help='添加代理(eg. "127.0.0.1:7890")')
return parser.parse_args()


Expand All @@ -45,9 +47,31 @@ async def visit(t, req, w, p):
conn.close()


def proxy(p: str):
if not p:
return
p = p.split(':')
try:
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, p[0], int(p[1]))
except IndexError or ValueError as e:
print(e)
return False
socket.socket = socks.socksocket
try:
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect(('admin.ddy.tjyun.com', 80))
conn.close()
except socks.ProxyConnectionError as e:
print(e)
return False
return True


async def main(args):
if not proxy(args.proxy):
return
req_content = bytes(f'GET /zm/jump/1 HTTP/1.1\r\nHost: admin.ddy.tjyun.com\r\nCookie: JSESSIONID={args.cookie}\r\n\r\n', encoding='utf-8')
tasks = [asyncio.create_task(visit(args.requests_num, req_content, args.wait, args.print)) for _ in range(args.tasks_num)]
tasks = [asyncio.create_task(visit(args.requests_num, req_content, args.wait, args.out)) for _ in range(args.tasks_num)]
await asyncio.wait(tasks)


Expand Down

0 comments on commit fedd7a9

Please sign in to comment.