声明:严禁用作非法目的,谢绝一切形式的转载。
如何实现远程打卡?远程打卡的问题在于你和公司处在不同的局域网之中,要实现远程打卡,虽然有些软件可以使用(比如向日葵、teamviwer等),但是实现功能也仅仅限于远程桌面控制(在免费的情况下,网速只能呵呵了)。如果想做其他的一些事情就无能为力了,比如访问内网的web服务、提升权限等等。
网络概况
本文不讲解怎么进行远程打卡。反过来讲解怎样在公司中访问在家庭里面的电脑,反之是同样的道理。(怕被和谐)
在上面的图中,第二个箭头画反了。直接通过公司局域网访问家庭局域网肯定是不行的。考虑借助公网来进行内网穿透,本文使用的工具是frpc。本文使用的公网ip是47.92.90.25,笔者自己租用的阿里云服务器,域名是www.hacksprit.top。
至于阿里云如何配置,域名如何进行绑定可以私信我。
frp
frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it supports TCP and UDP, as well as HTTP and HTTPS protocols, where requests can be forwarded to internal services by domain name. frp also has a P2P connect mode.
架构
基本使用
安装及配置文件
Firstly, download the latest programs from Release page according to
your operating system and architecture.
Put frps and frps.ini onto your server A with public IP.(公网ip)
Put frpc and frpc.ini onto your server B in LAN (that can't be connected
from public Internet).(局域网ip)
准备条件
家庭局域网开启ssh服务,开启一个PHP的web服务。其他服务根据需要自行安装,本文仅仅测试ssh服务和web服务。
(1) ssh服务 安装ssh服务
sudo apt-get install openssh-server
启动ssh服务
sudo /etc/init.d/ssh start
查看ssh服务是否启动成功
ssh -o port=22 burning@127.0.0.1
如果成功启动可看到如下所示的页面:(2) Web服务
通过如下的命令就可以开启一个web服务。
wget -O install.sh https://download.xp.cn/install.sh && sudo bash install.sh
Nginx的反向代理在后续文章中会介绍。简单来说就是Nginx代理内网服务器对外提供服务。而正向代理代理的是客户端的请求。
公司局域网ip地址
frp的配置和使用
(1) 公网47.92.90.25做为frp的服务器。编辑frps.ini。运行frps,开启服务端。设置http端口是7002。阿里云需要开启相应的端口,通过安全规则进行配置。
./frps -c frps.ini
(2) 家庭局域网192.168.42.36做为frp的客户端。编辑frpc.ini。
[common]server_addr = 47.92.90.25server_port = 7000[ssh]type = tcplocal_ip = 127.0.0.1local_port = 22remote_port = 6000[web]type = http local_port = 80 custom_domains = www.hacksprit.top
local_port = 80 是本地web服务的端口。
启动客户端frpc
./frpc -c frpc.ini
在frp服务器端看到如下信息:(2) 通过公司局域网进行测试
首先测试web服务: 在浏览器中输入www.hacksprit.top:7002成功访问到家庭局域网开启的服务。再测试ssh服务: 在终端输入命令
ssh -o port=6000 burning@47.92.90.25
最终成功访问家庭局域网的ssh服务。
写在最后
远程控制服务与此类似,添加相应的配置,就能轻松实现远程桌面控制。
公众号
更过内容,欢迎关注我的微信公众号:无情剑客。