V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
bugfan
V2EX  ›  分享创造

最近整了个无插件内网穿透工具

  •  
  •   bugfan ·
    bugfan · 2022-06-22 11:07:13 +08:00 · 3945 次点击
    这是一个创建于 887 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近整了一个内网穿透,用户方便的调试微信小程序,对外发布本地 web 服务,异地办公等。。。

    地址: i996.me
    23 条回复    2022-07-04 11:35:08 +08:00
    xuxuzhaozhao
        1
    xuxuzhaozhao  
       2022-06-22 11:22:18 +08:00
    Windows 好了,踢我一下,谢谢(*^▽^*)
    bugfan
        2
    bugfan  
    OP
       2022-06-22 11:25:41 +08:00
    @xuxuzhaozhao 好的😄
    ersic
        3
    ersic  
       2022-06-22 11:34:17 +08:00
    还要扫码关注。。。
    bugfan
        4
    bugfan  
    OP
       2022-06-22 11:38:09 +08:00
    @ersic 😂现在来不及做 web 界面,,主要是想限制用户隧道数量,哈哈哈
    fzdwx
        5
    fzdwx  
       2022-06-22 11:55:07 +08:00
    老哥可以交流一下。。。
    我也写了一个这种程序,github.com/fzdwx/burst
    这种 shell 实现的客户端确实好方便。。牛
    xiejieyin
        6
    xiejieyin  
       2022-06-22 11:57:00 +08:00 via Android
    先收藏 啥时开源 说一下 谢谢
    feller
        7
    feller  
       2022-06-22 11:59:33 +08:00
    收藏了
    muhuan
        8
    muhuan  
       2022-06-22 12:57:01 +08:00 via iPhone
    👍🏻
    bugfan
        9
    bugfan  
    OP
       2022-06-22 12:57:17 +08:00   ❤️ 1
    @fzdwx 你这个也不错,更安全,支持的协议也多


    @xiejieyin 😁好的
    youngbin0514
        10
    youngbin0514  
       2022-06-22 14:41:25 +08:00   ❤️ 1
    @fzdwx fork 大佬的源码学习一下
    fzdwx
        11
    fzdwx  
       2022-06-22 14:45:54 +08:00
    @youngbin0514 老哥你好,我也是边学习边写的,有什么疑问可以一起交流。哈哈哈
    jichangee
        12
    jichangee  
       2022-06-22 15:25:48 +08:00   ❤️ 1
    一直在用这个,也挺好用的
    https://localhost.run/
    saltbo
        13
    saltbo  
       2022-06-23 16:41:42 +08:00   ❤️ 1
    我去 shell 写客户端 牛

    我前段时间用 rust 写过一个 https://github.com/saltbo/rslocal
    bugfan
        14
    bugfan  
    OP
       2022-06-24 13:28:41 +08:00 via iPhone
    @saltbo 最近也在考虑要不要学 rust 呢,嘿嘿
    saltbo
        15
    saltbo  
       2022-06-26 11:33:58 +08:00
    @bugfan 欢迎入坑
    MiracleShadow
        16
    MiracleShadow  
       2022-06-27 09:50:18 +08:00
    Windows 可以考虑集成到 utools 这个工具里吗
    bugfan
        17
    bugfan  
    OP
       2022-06-27 16:20:59 +08:00   ❤️ 1
    @MiracleShadow 感谢关注,这个方式暂时不考虑了,我的初衷是客户端这边不装任何东西,拿来粘贴进去就能用。目前 windows 这边正在用 bat/vbs 进行开发
    MiracleShadow
        18
    MiracleShadow  
       2022-06-27 16:51:42 +08:00
    @bugfan #17 嗯嗯,bat 更方便。utools 可以增加一些流量,它的使用者们对内网穿透的呼声挺高的
    morphyhu
        19
    morphyhu  
       2022-06-28 23:12:30 +08:00
    #!/usr/bin/env bash
    #
    # Description: A Nat Script by sean bugfan
    #
    # Copyright (C) 2022 - Now bugfan <[email protected]>
    # URL: i996.me
    # https://github.com/bugfan
    #
    access_token=$1
    pipe_dir="/tmp/clotho/"
    if [ -d ${pipe_dir} ]; then
    rm -rf ${pipe_dir}
    fi
    if [ ! -d ${pipe_dir} ]; then
    mkdir ${pipe_dir}
    fi
    pipe_websocket=$(echo ${pipe_dir}"websocket")
    if [ ! -p ${pipe_websocket} ]; then
    mkfifo ${pipe_websocket}
    fi
    pipe_internal=$(echo ${pipe_dir}"internal")
    if [ ! -p ${pipe_internal} ]; then
    mkfifo ${pipe_internal}
    fi

    message_request="ClothoHTTPRequest"
    message_broadcast="ClothoBroadcast"
    message_break="ClothoBreakClient"
    message_key="ClothoMsg"


    sys_protocol="https://"
    sys_host="api.i996.me"
    public_api_protocol="https://"
    public_host="xxxx.i996.me"
    private_host="127.0.0.1:8080"
    wxtoken="xxxx"

    include(){
    tmp=$(echo $1 | grep "${2}")
    if [[ "$tmp" != "" ]]
    then
    return 1
    else
    return 0
    fi
    }

    check_token(){
    if [ -z "${1}" ]; then
    return 1
    fi
    msg=$(curl -s --http1.1 -X POST ''$sys_protocol$sys_host'/sys-auth' -H 'Authorization: '${1}'')
    if [ $? != 0 ]; then
    return 2
    fi

    include $msg $message_broadcast
    stat=$?
    if [ ${#msg} == '0' ]; then
    return 1
    fi
    if [ $stat == 0 ]; then
    return 1
    fi
    wxtoken=${1}
    info=${msg#*$message_broadcast}
    private_host=${info#*|}
    public_host=${info%%|*}
    # echo 'forward a:'$private_host
    # echo 'forward b:'$public_host
    # echo 'forward c:'$wxtoken
    return 0
    }

    init(){
    while :
    do
    # # read token
    # echo "请输入 Token: \c"
    # token=''
    # while : ;
    # do
    # read -n 1 -s -p "" pw
    # if [ $pw ]; then
    # token=${token}$pw
    # echo "*\c"
    # else
    # echo
    # break
    # fi
    # done

    # # read token
    # # read -p "请输入 Token:" token
    # check_token $token
    # state=$?
    # if [ $state == 0 ]; then
    # break
    # fi
    # if [ $state == 2 ]; then
    # echo '抱歉,服务器可能暂时出了点问题!请稍后再尝试~'
    # else
    # echo 'Token 验证失败!请关注"敲代码斯基"公众号获取 Token!(免费)'
    # fi

    # check token
    token=${access_token}
    if [ ${#token} == '0' ];then
    echo '请指定 Token 参数!(curl -s i996.me | bash -s Token)'
    exit 0
    fi
    check_token $token
    state=$?
    if [ $state == 0 ]; then
    break
    fi
    if [ $state == 2 ]; then
    echo '抱歉,服务器可能暂时出了点问题!请稍后再尝试~'
    else
    echo 'Token 验证失败!请关注"敲代码斯基"公众号获取 Token!(免费)'
    fi
    exit 0
    done

    }

    init

    new_fifo_name(){
    echo $1$2
    }

    string_index(){
    x="${1%%$2*}"
    [[ $x = $1 ]] && echo -1 || echo ${#x}
    }
    do_request(){
    # get message id
    tmp="${1#*${message_key}:}"
    message_id=${tmp%%\'*}
    if [ ${#message_id} -lt 5 ]; then
    printf "error message:%s\n" $message_id
    return
    fi
    echo "==== request ====>:"$message_id

    internal_fifo=$(new_fifo_name ${pipe_dir} ${message_id})
    mkfifo ${internal_fifo}
    response ${message_id} ${internal_fifo} &
    (eval "$1") > ${internal_fifo}
    # echo "===tunnel-client curl exit state===>:"$?
    rm ${internal_fifo}
    }

    response(){
    # printf 'normal msg id is:%s,%s\n' $1 $2
    curl -X POST --http1.1 -v ''$sys_protocol$sys_host'/sys-callback' -H 'Authorization: '${wxtoken}'' -H 'ClothoMsg: '${1}'' --data-binary '@'${2}'' 2>/dev/null
    echo "<==== response ====:"${1}
    }

    handle(){
    msg=${1}
    # printf "===message===>:%s\n" ${msg}
    include $msg $message_request
    req=$?
    if [ $req > 0 ]; then
    payload=${msg#*$message_request}
    # printf "%s\n" $payload
    cmd=$(echo $payload|base64 -d)
    # cmd="curl -X 'GET' -d '' -H 'Accept: */*' -H 'ClothoMsg: '${wxtoken}'' -H 'User-Agent: curl/7.77.0' 'http://127.0.0.1:9090'"
    do_request "$cmd" &
    fi

    # if [ $msg == *$message_break* ]; then
    # echo '远端更新了,请输入 Token 重新启动!!'
    # exit 0
    # fi

    }
    ssh_response(){
    while :
    do
    read msg < ${pipe_internal}
    printf 'normal msg is:%s\n' $msg
    curl -X POST --http1.1 -v ''$sys_protocol$sys_host'/sys-callback' -H 'Authorization: '${wxtoken}'' -H 'ClothoMsg: '${msg}'' --data-binary '@'${pipe_internal}''
    echo "----send response ok ----\n"

    done
    echo "finish ssh_response\n"
    }

    read_io(){
    # tail -f ${pipe_websocket} | while read -r line ; do
    echo "It works!!! "
    while IFS= read -r line ; do
    handle "${line}"
    done < "${pipe_websocket}"
    echo "Connect exception...\n"
    }


    sys_connect(){
    # listen conn
    read_io & 2>/dev/null
    read_io_pid=$!
    # printf "worker pid:%s\n" ${read_io_pid}

    # ssh_response &
    # ssh_response_pid=$!
    # printf "read response pid:%s\n" ${ssh_response_pid}

    # do connect
    curl -s --no-buffer --http1.1 -H 'Authorization: '${wxtoken}'' -H 'Connection: keep-alive, Upgrade' -H 'Upgrade: websocket' -v -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: websocket' ''$sys_protocol$sys_host'/sys-ws' ws -o ${pipe_websocket} 2>/dev/null
    echo "System connection has broken! Retry...."
    kill ${read_io_pid} 2>/dev/null
    }

    # finish func
    finish () {
    kill ${read_io_pid}
    rm -rf ${pipe_dir}
    rm 0
    exit 0
    }

    # catch "Exit"
    # catch "Ctrl + c"
    trap finish EXIT SIGTERM SIGINT SIGQUIT

    run(){
    while :
    do
    sys_connect
    sleep 5
    done
    }

    run


    # # Inifinite sleep
    # sleep infinity
    # wait $!
    sunmoon1983
        20
    sunmoon1983  
       2022-06-29 15:57:41 +08:00
    @jichangee 这个好,简单、方便
    bugfan
        21
    bugfan  
    OP
       2022-07-01 16:50:31 +08:00
    @xuxuzhaozhao windows 开发好了老铁,欢迎试用 👏
    https://github.com/bugfan/i996
    https://www.i996.me (官网有些许的潦草,见谅哈)
    xuxuzhaozhao
        22
    xuxuzhaozhao  
       2022-07-04 11:30:50 +08:00
    @bugfan #21 搞起搞起
    bugfan
        23
    bugfan  
    OP
       2022-07-04 11:35:08 +08:00
    @xuxuzhaozhao 如果你是 win10 以上,建议用 windows wsl/linux ;如果<=win10,建议用自带终端那种方式。windows 版本不同还有限制😂
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3018 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:49 · PVG 22:49 · LAX 06:49 · JFK 09:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.