# push-public-ip **Repository Path**: smewl13/push-public-ip ## Basic Information - **Project Name**: push-public-ip - **Description**: 一个用于自动推送公共IP地址的开源项目,适用于动态IP环境,帮助用户实时更新和管理设备的公网IP。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-07 - **Last Updated**: 2026-01-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # push-public-ip 一个用于获取公网IP地址并通过企业微信或邮件发送通知的工具。 ## 功能特性 - 📡 自动获取公网IP地址 - 📧 支持邮件通知(SMTP协议) - 💬 支持企业微信群机器人通知 - 🔒 使用SM4加密算法保护敏感信息 - 📊 支持数据库存储历史IP记录(SQLite) - 📝 完善的日志系统 - 🎯 支持HTML和纯文本两种通知格式 ## 安装 ### 二进制安装 直接下载对应平台的二进制文件即可使用: ```bash tar -xvf push-public-ip.*.tar.gz -C /usr/local/ ``` ### 源码编译 ```bash git clone https://gitee.com/smewl13/push-public-ip.git cd push-public-ip make build ``` ## 使用方法 ### 基本使用 ```bash # 进入安装目录 cd /usr/local/push-public-ip # 使用默认配置文件 ./push-public-ip # 指定配置文件路径 ./push-public-ip -c /path/to/config.toml ``` ### 命令行参数 ``` ./push-public-ip --help ``` | 参数 | 别名 | 描述 | 默认值 | |------|------|------|--------| | `--config` | `-c` | 配置文件路径 | `configs/config.toml` | | `--version` | `-v` | 显示版本信息 | - | ### SM4加密命令 用于加密敏感信息(如邮箱密码、企业微信机器人URL): ```bash ./push-public-ip sm4 "your-sensitive-info" ``` ## 配置说明 配置文件使用TOML格式,默认位于`configs/config.toml`。 ### 公网IP配置 ```toml [public_ip] # 公网地址内容的格式,目前支持html、text,默认text encoding = "text" # 获取公网地址的url url = "https://ip.3322.net/" ``` ### 数据库配置 ```toml [database] type = "sqlite" ``` ### 邮件通知配置 可以配置多个邮件通知: ```toml [[mail]] enable = true name = "测试" server="smtp.163.com" port=465 user="your-email@163.com" addrs=["recipient1@example.com", "recipient2@example.com"] subject="最新公网IP信息" password="加密后的密码" ``` ### 企业微信通知配置 可以配置多个企业微信群机器人: ```toml [[wxwork]] enable = false name = "运维群" url = "加密后的企业微信机器人URL" ``` ### 日志配置 ```toml [log] # 日志级别: debug, info, warn, error level = "debug" # 日志格式: text, json encoding = "text" # 日志输出方式: file, console handle = ["file", "console"] # 日志存储路径 # dir = "log" # 日志保存时长(天) max_age = 7 # 每个文件最大大小(MB) max_size = 200 ``` ## 加密说明 为了保护敏感信息(如邮箱密码、企业微信机器人URL),需要使用SM4加密算法进行加密: ```bash ./push-public-ip sm4 "your-sensitive-info" ``` 将生成的密文填入配置文件中。 ## 运行机制 1. 程序启动后会从配置的URL获取公网IP 2. 与数据库中存储的上次IP进行比较 3. 如果IP发生变化,会通过配置的通知方式发送通知 4. 将新的IP信息存储到数据库 5. 程序退出 ## 部署建议 可以将该工具添加到crontab中定期执行: ```bash # 每5分钟执行一次 */5 * * * * /usr/local/push-public-ip/push-public-ip -c /path/to/config.toml ``` ## 依赖项 - [github.com/urfave/cli/v2](https://github.com/urfave/cli/v2) - 命令行接口 - [gitee.com/smewl13/toolkit/lcrypto](https://gitee.com/smewl13/toolkit) - 加密工具库 ## 许可证 MIT License ## 作者 smewl13