Python自动化脚本:2分钟快速搭建MTProto代理服务(支持多端口负载均衡)
安装docker:
apt install -y docker docker-compose curl
手动创建脚本,你可以在服务器上执行
nano mtproxy.sh
黏贴代码
#!/bin/bash
WORKDIR=$(dirname $(readlink -f $0))
cd $WORKDIR
function get_ip_public() {
public_ip=$(curl -s https://api.ip.sb/ip -A Mozilla --ipv4)
[ -z "$public_ip" ] && public_ip=$(curl -s ipinfo.io/ip -A Mozilla --ipv4)
echo $public_ip
}
function install_docker() {
if ! command -v docker &> /dev/null; then
echo "Docker 未安装,正在安装..."
if [[ -f /etc/redhat-release ]]; then
yum install -y docker
elif [[ -f /etc/debian_version ]]; then
apt-get update && apt-get install -y docker.io
fi
systemctl enable docker && systemctl start docker
fi
echo "Docker 已安装。"
}
function config_mtp() {
echo -e "请输入 MTProto 代理的端口(默认 443):"
read -p "(默认端口: 443):" input_port
[ -z "${input_port}" ] && input_port=443
echo -e "请输入需要伪装的域名(默认 itunes.apple.com):"
read -p "(默认域名: itunes.apple.com):" input_domain
[ -z "${input_domain}" ] && input_domain="itunes.apple.com"
echo -e "请输入 MTProto Secret(留空则随机生成):"
read -p "(自动生成 Secret):" input_secret
[ -z "${input_secret}" ] && input_secret=$(openssl rand -hex 16)
echo "PORT=${input_port}" > .env
echo "FAKE_TLS_DOMAIN=${input_domain}" >> .env
echo "SECRET=${input_secret}" >> .env
}
# 运行 Docker 容器
function run_mtp() {
echo "正在启动 MTProto Proxy..."
docker run -d \
--name=mtproto-proxy \
--restart=always \
-p ${PORT}:443 \
-e SECRET=${SECRET} \
-e FAKE_TLS_DOMAIN=${FAKE_TLS_DOMAIN} \
telegrammessenger/proxy:latest
sleep 2
# 生成 Telegram 代理链接
public_ip=$(get_ip_public)
client_secret="ee${SECRET}$(xxd -pu <<<${FAKE_TLS_DOMAIN} | sed 's/0a//g')"
echo
✅ 获取代理链接