Commit 53d6062f authored by 郭阔's avatar 郭阔

feat: ip-check.sh IP 类型判定(数据中心/住宅/移动/代理);墙审计快照自动归类出口 IP

parent 86cc8a75
#!/bin/bash
# ip-check.sh [ip ...] - 判断出口 IP 类型:数据中心/住宅/移动/代理
# 无参数=检测当前出口 IP。数据来源:ip-api.com(hosting/proxy/mobile 字段)+ ASN 归属。
set -uo pipefail
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
ips=("$@")
if [ ${#ips[@]} -eq 0 ]; then
_cur="$(curl -s --max-time 8 https://api.ipify.org)" || _cur=""
[ -n "$_cur" ] || { echo "❌ 取当前出口 IP 失败"; exit 1; }
ips=("$_cur")
fi
for ip in "${ips[@]}"; do
j="$(curl -s --max-time 10 "http://ip-api.com/json/${ip}?fields=status,country,city,isp,org,as,hosting,proxy,mobile,reverse&lang=zh-CN")"
if [ "$(echo "$j" | jq -r '.status // ""' 2>/dev/null)" != "success" ]; then
echo "$ip ❓ 查询失败:$(echo "$j" | head -c 80)"
continue
fi
hosting="$(echo "$j" | jq -r '.hosting')"; proxy="$(echo "$j" | jq -r '.proxy')"; mobile="$(echo "$j" | jq -r '.mobile')"
if [ "$hosting" = "true" ]; then kind="🏢 数据中心/主机商"; elif [ "$mobile" = "true" ]; then kind="📱 移动网络"; else kind="🏠 住宅/家宽"; fi
[ "$proxy" = "true" ] && kind="$kind + 🚩代理标记"
printf "%s %s\n %s | %s | %s | 反查:%s\n" "$ip" "$kind" \
"$(echo "$j" | jq -r '.as')" "$(echo "$j" | jq -r '.isp')" "$(echo "$j" | jq -r '.country')$(echo "$j" | jq -r '.city' | sed 's/^/·/')" \
"$(echo "$j" | jq -r '.reverse // "-"')"
done
......@@ -38,6 +38,19 @@ for line in sh("scutil --proxy").splitlines():
k, v = line.split(" : ", 1); proxy[k.strip()] = v.strip()
snap["systemProxy"] = proxy
snap["vpnInterfaces"] = [l.split(":")[0].strip() for l in sh("ifconfig -l").split() if l.startswith("utun")]
ip = snap.get("egressIP", "")
if ip:
import urllib.request
try:
with urllib.request.urlopen(f"http://ip-api.com/json/{ip}?fields=hosting,proxy,mobile,as", timeout=8) as r:
c = json.loads(r.read())
if c.get("hosting"): cls = "数据中心"
elif c.get("mobile"): cls = "移动网络"
else: cls = "住宅"
if c.get("proxy"): cls += "+代理标记"
snap["egressIPClass"] = f"{cls} ({c.get('as','')})"
except Exception:
snap["egressIPClass"] = "判定失败"
json.dump(snap, open(p, "w"), ensure_ascii=False, indent=2)
print(f" 系统代理: HTTP={proxy.get('HTTPEnable','?')} HTTPS={proxy.get('HTTPSEnable','?')} SOCKS={proxy.get('SOCKSEnable','?')}"
+ (f" ({proxy.get('HTTPProxy','')}:{proxy.get('HTTPPort','')})" if proxy.get('HTTPEnable') == '1' else "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment