DropTemporaryTo 使用本地防火墙临时拦截IP数据包
(ip string, expiresAt int64)
| 8 | |
| 9 | // DropTemporaryTo 使用本地防火墙临时拦截IP数据包 |
| 10 | func DropTemporaryTo(ip string, expiresAt int64) { |
| 11 | // 如果为0,则表示是长期有效 |
| 12 | if expiresAt <= 0 { |
| 13 | expiresAt = time.Now().Unix() + 3600 |
| 14 | } |
| 15 | |
| 16 | var timeout = expiresAt - time.Now().Unix() |
| 17 | if timeout < 1 { |
| 18 | return |
| 19 | } |
| 20 | if timeout > 3600 { |
| 21 | timeout = 3600 |
| 22 | } |
| 23 | |
| 24 | // 使用本地防火墙延长封禁 |
| 25 | var fw = Firewall() |
| 26 | if fw != nil && !fw.IsMock() { |
| 27 | // 这里 int(int64) 转换的前提是限制了 timeout <= 3600,否则将有整型溢出的风险 |
| 28 | _ = fw.DropSourceIP(ip, int(timeout), true) |
| 29 | } |
| 30 | } |
no test coverage detected