forked from LOWERTOP/Shadowrocket-First
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCP-Cal.html
146 lines (125 loc) · 4.23 KB
/
TCP-Cal.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TCP缓冲区计算器</title>
<!-- Favicon 设置 -->
<link rel="icon" type="image/svg+xml" href="https://cdn.jsdelivr.net/npm/simple-icons@v9/icons/github.svg">
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.calculator {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.input-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 200px;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
padding: 15px;
background-color: #e8f5e9;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="calculator">
<h1>TCP缓冲区计算器</h1>
<div class="input-group">
<label for="bandwidth">瓶颈带宽 (Mbps),本地带宽和服务端带宽选最小带宽:</label>
<input type="number" id="bandwidth" placeholder="例如: 600">
</div>
<div class="input-group">
<label for="rtt">RTT 往返时间 (毫秒),一般指 Ping 值:</label>
<input type="number" id="rtt" placeholder="例如: 170">
</div>
<button onclick="calculateBDP()">计算</button>
<div class="result" id="result" style="display: none;">
<h3>计算结果:</h3>
<p>BDP (比特) = <span id="bdpBits"></span> bits</p>
<p>BDP (字节) = <span id="bdpBytes"></span> bytes</p>
<div class="adjustment">
<button onclick="adjustValue(-1)">-1 MiB</button>
<button onclick="adjustValue(-5)">-5 MiB</button>
<button onclick="adjustValue(1)">+1 MiB</button>
<button onclick="adjustValue(5)">+5 MiB</button>
</div>
<h3>建议的 TCP 缓冲区设置:</h3>
<p>net.ipv4.tcp_wmem="4096 16384 <span id="recommendedWmem"></span>"</p>
<p>net.ipv4.tcp_rmem="4096 87380 <span id="recommendedRmem"></span>"</p>
<button onclick="generateScript()">生成永久保存脚本</button>
<div id="script" style="display: none;">
<h3>永久保存脚本:</h3>
<pre id="scriptContent"></pre>
</div>
</div>
</div>
<script>
let currentBdpBytes = 0;
function calculateBDP() {
const bandwidth = document.getElementById('bandwidth').value;
const rtt = document.getElementById('rtt').value;
const bps = bandwidth * 1000000;
const rttSeconds = rtt / 1000;
const bdpBits = bps * rttSeconds;
currentBdpBytes = Math.ceil(bdpBits / 8);
updateDisplay();
}
function adjustValue(mebibytes) {
const adjustment = mebibytes * 1024 * 1024; // 转换 MiB 为字节
currentBdpBytes = Math.max(0, currentBdpBytes + adjustment);
updateDisplay();
}
function updateDisplay() {
document.getElementById('bdpBits').textContent = (currentBdpBytes * 8);
document.getElementById('bdpBytes').textContent = currentBdpBytes;
document.getElementById('recommendedWmem').textContent = currentBdpBytes;
document.getElementById('recommendedRmem').textContent = currentBdpBytes;
document.getElementById('result').style.display = 'block';
}
function generateScript() {
const scriptContent = `#!/bin/bash
# 设置TCP缓冲区大小
sysctl -w net.ipv4.tcp_wmem="4096 16384 ${currentBdpBytes}"
sysctl -w net.ipv4.tcp_rmem="4096 87380 ${currentBdpBytes}"
# 将设置写入/etc/sysctl.conf以便永久保存
echo "net.ipv4.tcp_wmem = 4096 16384 ${currentBdpBytes}" >> /etc/sysctl.conf
echo "net.ipv4.tcp_rmem = 4096 87380 ${currentBdpBytes}" >> /etc/sysctl.conf
# 应用更改
sysctl -p`;
document.getElementById('scriptContent').textContent = scriptContent;
document.getElementById('script').style.display = 'block';
}
</script>
</body>
</html>