[我的小项目] 天翼网关路由器命令行客户端

陪她去流浪 桃子 2019年06月23日 阅读次数:5085

这几天在外面玩,晚上无聊想看看电影,考虑到家里的树莓派已经整日整夜地下载,已经下载了很多电影了,所以想直接想以 Samba/WebDAV 的方式连接到家里面进行观看SFTP 可以直接通过 SSH 连接,非常方便。 Samba / WebDAV 不再使用。

无聊的是,我忘记开放 Samba 的端口了,而且路由器的端口映射需要在路由器的管理页面才能进行操作,所以无奈放弃。准备回家分析一下路由器的协议自己写一个命令行配置客户端。 既然已经写下这篇文章了,说明我的客户端已经写好了。对,没错。回到家就开始写,花了两三个小时时间分析协议和写实现。对于我的路由器来说,完美运行。

但是,路由器种类那么多,所以没办法兼容所有型号,现在这个只针对:天翼网关(GPON)。

项目开源地址:https://github.com/movsb/gpon-client

以下是一些帮助和使用说明:

$ ./gpon-client
./gpon-client 
A GPON (Tiānyì Gateway) client used to modify router configurations

Usage:
  ./gpon-client [command]

Available Commands:
  devices     manage devices
  gwinfo      show gateway information
  help        Help about any command
  portmaps    manage port mappings

Flags:
  -h, --help   help for ./gpon-client

Use "./gpon-client [command] --help" for more information about a command.

运行环境初始化配置

请先在命令行下导出几个环境变量。

# 路由器IP地址,默认 192.168.1.1
$ export IP=192.168.1.1

# 路由器用户名,默认 useradmin
$ export USERNAME=useradmin

# 路由器密码,无默认
$ export PASSWORD=

示例使用

网关信息

$ ./gpon-client gwinfo
LAN IPv4: 192.168.1.1
WAN IPv4: 116.7.8.92
MAC     : 6C38654BA310

设备列表

$ ./gpon-client devices list
Name      Wired  IPv4             Upload Speed    Download Speed    Type      System    MAC           
----------------------------------------------------------------------------------------------------
dev1      true   192.168.1.3        415.22KB/s         26.96KB/s    -         -         DCA63266E6AD  
dev1      false  192.168.1.2              0B/s              0B/s    phone     ios       F838808FDD44

端口转发配置

枚举端口映射

$ ./gpon-client portmaps list
ID   Name            Protocol    OuterPort   InnerIP             InnerPort   Enable
-----------------------------------------------------------------------------------
1    test            BOTH        4321        192.168.1.6         1234        1     
2    nginx           TCP         8888        192.168.1.6         8888        1     
3    ssh             TCP         10022       192.168.1.6         22          1     
4    bt              BOTH        8999        192.168.1.6         8999        1     
5    https           TCP         443         192.168.1.6         443         1  

添加端口映射

$ ./gpon-client portmaps create nginx BOTH 443 192.168.1.6 443

删除端口映射

$ ./gpon-client portmaps delete nginx

启用端口映射

$ ./gpon-client portmaps enable nginx

禁用端口映射

$ ./gpon-client portmaps disable nginx

这篇文章的内容已被作者标记为“过时”/“需要更新”/“不具参考意义”。