超强,废弃手机用来做服务器,不用root,外网可访问!

本文教你如何利用废弃手机搭建服务器并进行内网穿透,通过Termux安装Python,创建Flask项目,使用cpolar实现外网访问。步骤简单,包括下载Termux、配置Python环境、编写run.py脚本、注册cpolar账号并设置隧道,最终成功在外网访问到服务器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

成功

在这里插入图片描述

废弃手机秒变服务器

现在几乎每人家里都有很多废弃的手机,如果将它们变为服务器岂不是很香,搭个简单的文件服务器做网盘用!链接家里的wifi,链接充电器,7724不间断工作,还省了一大笔云服务器费用,想到就动手,几行代码就实现了将网站布置起来,并且公布到外网,随便一个人都能访问,简单又快捷!

第一步

下载安装Termux
下载地址:https://termux.com/
github地址:https://github.com/termux

获得文件管理权限
在终端当中输入termux-setup-storage

第二步

自动换源,下载速度较快

sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list 
sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list 
sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list 
pkg update

第三步

进入自己的python脚本位置
列如我的:

cd /;cd sdcard/cxk_python/linux_page

在这里插入图片描述
下载安装python

pkg install python
pip install --upgrade pip -i https://pypi.doubanio.com/simple
pip install flask -i https://pypi.doubanio.com/simple
pip install psutil -i https://pypi.doubanio.com/simple

完成之后编写flask项目

run.py
# -*- coding:utf-8 -*-
from flask import *
import json,os,datetime,random
import shutil
import _thread
import time

app = Flask(__name__)
app.config.from_object(__name__)
def GetNameByEveryDir(file_dir):  
    # Input   Root Dir and get all img in per Dir.
    # Out     Every img with its filename and its dir and its path  
    FileNameWithPath = [] 
    FileName         = []
    FileDir          = []
    for root, dirs, files in os.walk(file_dir):  
        for file in files:  
            FileNameWithPath.append(os.path.join(root, file
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

智能视界探索者

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

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

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

打赏作者

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

抵扣说明:

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

余额充值