编写一个流量消耗器

校园卡一个月49,将近300G的流量和400分钟通话,每月用不完就会显得很亏,所以需要一个消耗流量的工具

为了能随时随地消耗流量,这个工具需要有极佳的跨平台能力,所以我选择B/S架构,无论在哪个平台,只要有浏览器就能用

我在网上找到了这个项目https://github.com/shidahuilang/flow-consumer/ ,但并不是很好,比如包含了跟踪器和禁用f12(我真想不明白你一个开源项目禁用f12干什么…意义不明)

基于这个项目,我编写(复制粘贴)了一个非常轻量的流量消耗器,只有短短200行的html代码和两个js库

在线体验:https://crackme.net/tools/fuck_isp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="referrer" content="no-referrer" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>流量消耗器</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios@1.7.7/dist/axios.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 20px;
line-height: 1.6;
}
.container {
max-width: 600px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
select,
input[type="number"],
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
border: none;
color: white;
font-size: 16px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
p {
font-size: 16px;
margin: 10px 0;
}
strong {
color: #007bff;
}
@media (max-width: 600px) {
.container {
padding: 15px;
}
}
</style>
</head>
<body>
<div id="app" class="container">
<div>
<label for="input">下载节点</label>
<select type="text" v-model="set.input" class="form-control">
<option value="https://speed.cloudflare.com/__down?bytes=100000000" selected="selected">[默认] cloudflare 100MB</option>
<option value="https://www.cucloud.cn/templets/1/default/images/nodes-overview-bg.png">联通云</option>
<option value="https://cd.pddpic.com/android_dev/2024-10-29/2cbce5a94a1ff8cb4e8125a114960a03.apk">拼多多</option>
<option value="https://i0.hdslb.com/bfs/article/d435b548d27ec95c226c6d217210d98d22682236.gif">bilibili</option>
<option value="https://lf1-cdn-tos.bytegoofy.com/goofy/ies/douyin_home_web/imgs/mob_1-1.15453147.gif">抖音</option>
</select>
<input type="text" v-model="set.input" placeholder="下载链接" class="form-control" autocomplete="off" />
</div>
<div>
<label for="threads">线程</label>
<input type="number" v-model="set.thread" min="1" />
</div>
<div>
<button @click="run">{{set.status?'停止':'开始'}}</button>
</div>
<div>
<p><strong>速度:</strong> {{speed}}</p>
<p><strong>用时:</strong> {{FormatTime(spend)}}</p>
<p><strong>已消耗流量:</strong> {{FormatSize(waste)}}</p>
</div>
</div>
<script>
var errors = null;
new Vue({
el: "#app",
data: {
set: {
input: "https://speed.cloudflare.com/__down?bytes=100000000",
output: "",
infinite: true,
status: false,
thread: 1,
},
tasks: [],
speed: "0",
spend: 0,
waste: 0,
timer: null,
cancelSource: axios.CancelToken.source(),
},
watch: {
async "set.status"(newVal) {
if (newVal) {
this.cancelSource = axios.CancelToken.source();
this.timer = setInterval(() => {
this.speed =
this.FormatSize(
this.tasks.reduce(function (prev, curr) {
return prev + curr;
}, 0)
) + "/s";
this.spend++;
}, 1000);
do {
await new Promise((resolve) => {
let task = [];
for (let i = 0; i < this.set.thread; i++) {
task.push(this.download(Math.random().toString(36).substr(2, 10)));
}
Promise.all(task).finally(resolve);
});
} while (this.set.status && this.set.infinite);
} else {
clearInterval(this.timer);
this.cancelSource.cancel();
}
},
},
methods: {
run() {
this.set.status = !this.set.status;
},
download(id) {
let loaded = 0;
let speed = 0;
let timestamp = new Date().getTime();
let that = this;
const index = this.tasks.push(speed) - 1;
return axios
.request({
url: this.set.input,
params: {
[id]: id,
},
cancelToken: this.cancelSource.token,
onDownloadProgress: function (progressEvent) {
const now = new Date().getTime();
speed = ((progressEvent.loaded - loaded) / (now - timestamp)) * 1000;
that.tasks[index] = speed;
that.waste += progressEvent.loaded - loaded;
loaded = progressEvent.loaded;
timestamp = now;
},
})
.catch((e) => {
if (!axios.isCancel(e)) {
this.set.status = false;
window.alert(e.message);
}
})
.finally(() => {
delete that.tasks[index];
});
},
FormatTime(second) {
if (second < 0) return "";

const hour = Math.floor(second / 3600);
const min = Math.floor(second / 60) % 60;
const sec = second % 60;

const hourStr = hour > 0 ? `${hour < 10 ? "0" : ""}${hour}h` : "";
const minStr = hour > 0 || min > 0 ? `${min < 10 ? "0" : ""}${min}m` : "";
const secStr = `${sec < 10 ? "0" : ""}${sec}s`;

return hourStr + minStr + secStr;
},
FormatSize(bytes) {
if (bytes === 0) return "0 Bytes";

const i = Math.floor(Math.log(bytes) / Math.log(1000));
return parseFloat((bytes / Math.pow(1000, i)).toFixed(2)) + " " + ["Bytes", "KB", "MB", "GB", "TB", "PB", "WTF"][i];
},
},
});
</script>
</body>
</html>

编写一个流量消耗器
https://crackme.net/articles/fuck_isp/
作者
Brassinolide
发布于
2024年11月2日
许可协议