github.com/TeaOSLab/EdgeNode@v1.3.8/internal/firewalls/utils.go (about) 1 // Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package firewalls 4 5 import ( 6 "time" 7 ) 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 }