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

✅ 获取代理链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白马区块Crypto100

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值