Skip to content

Simple go program to broadcast IP / 简单的广播IP的go程序

Notifications You must be signed in to change notification settings

7Ji/router_reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple go program to be used on the router (mainly OpenWrt) to listen on a specific port and report the IP address on a specific interface to multiple clients in a set interval.
简单的用在路由器(主要是OpenWrt)上的用于在特定端口上监听并以恒定间隔向多个客户端广播的程序

I wrote this program so I could have a QQ bot to run on a internal server to watch on the router's public IP and notify me if its IP has changed, without relying on external IP reporting services (e.g. ipw.cn).
写这个程序的目的是为了在内网服务器上跑QQ机器人,监视路由器的公网IP,并且在IP变动的情况下来汇报,而不依赖外部的IP汇报服务(比如ipw.cn)

The file openwrt_router_reporter.procd.service should be modified with iface and listen set according to your actual network configuration, and placed as /etc/init.d/router_reporter and with mod 755 to be enabled on an OpenWrt device 文件openwrt_router_reporter.procd.service里面的ifacelisten根据具体网络配置修改后,应当被放置为/etc/init.d/router_reporter并且设置权限为755来在OpenWrt设备上开机自启

The command to compile the program to be run on a MIPSLE softfloat platform (e.g. MT7621, the SoC used by Phicomm K2P and Xiaomi Redmi AC2100):
编译在一个小端MIPS软浮点平台(比如说斐讯K2P和红米AC2100上的SoC MT7621)上运行的程序的命令

GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -buildid=" -trimpath

Go can cross-compile easily without extra setting about the toolchain, the above command can be simply run on an x86-64 host natively Go可以简单地不经额外工具链设置就能交叉编译,上面的命令可以在x86-64的机子上原生运行

$ uname -a
Linux laptop7ji 6.0.8-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 10 Nov 2022 21:14:22 +0000 x86_64 GNU/Linux
$ GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -buildid=" -trimpath
$ file router_reporter
router_reporter: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, stripped

To test if it is running correctly, simple use nc:
要检查是否正常运行,可以简单地使用nc

nc [listen host] [listen port]

Expected output:
正常的输出:

$ nc 127.0.0.1 7777
192.168.7.25/24
192.168.7.25/24
192.168.7.25/24
192.168.7.25/24

About

Simple go program to broadcast IP / 简单的广播IP的go程序

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published