新版本采用libipset库操作ipset集合,采用libpcap、libcap抓包获取源IP
This commit is contained in:
Binary file not shown.
@@ -5,18 +5,22 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type IPInfo struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
Continent string `json:"continent"`
|
||||
Country string `json:"country"`
|
||||
} `json:"data"`
|
||||
IP string `json:"ip"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func isValidIP(ip string) bool {
|
||||
return net.ParseIP(ip) != nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -24,16 +28,29 @@ func main() {
|
||||
log.Fatalf("用法: %s <IP>", os.Args[0])
|
||||
}
|
||||
|
||||
ip := os.Args[1]
|
||||
if !isValidIP(ip) {
|
||||
log.Fatalf("无效的 IP 地址: %s", ip)
|
||||
}
|
||||
|
||||
// 目标 URL
|
||||
url := "https://qifu.baidu.com/ip/geo/v1/district?ip=" + os.Args[1]
|
||||
url := "https://qifu.baidu.com/ip/geo/v1/district?ip=" + ip
|
||||
|
||||
// 创建 HTTP 客户端并设置超时时间
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
|
||||
// 发送 GET 请求
|
||||
resp, err := http.Get(url)
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
log.Fatalf("发送 GET 请求时出错: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 检查 HTTP 响应状态码
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Fatalf("HTTP 请求失败,状态码: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// 读取响应体
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user