64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
IP 欺诈度检查脚本 - 通过 scamalytics.com 查询 Fraud Score
|
|
用法: python check_fraud.py <ip> [proxy_host:proxy_port:user:pass]
|
|
输出: JSON { "success": true, "ip": "x.x.x.x", "score": 12 }
|
|
|
|
支持通过 SOCKS5 代理访问 scamalytics(绕 CF 更稳定)
|
|
"""
|
|
|
|
import sys
|
|
import re
|
|
import json
|
|
import cloudscraper
|
|
|
|
def check_fraud(ip, proxy_str=None):
|
|
try:
|
|
url = f"https://scamalytics.com/ip/{ip}"
|
|
scraper = cloudscraper.create_scraper(
|
|
browser={
|
|
'browser': 'chrome',
|
|
'platform': 'windows',
|
|
'desktop': True,
|
|
}
|
|
)
|
|
|
|
# 构建代理
|
|
proxies = None
|
|
if proxy_str:
|
|
parts = proxy_str.split(':')
|
|
if len(parts) >= 2:
|
|
host = parts[0]
|
|
port = parts[1]
|
|
user = parts[2] if len(parts) > 2 else ''
|
|
pwd = parts[3] if len(parts) > 3 else ''
|
|
if user and pwd:
|
|
proxy_url = f"socks5h://{user}:{pwd}@{host}:{port}"
|
|
else:
|
|
proxy_url = f"socks5h://{host}:{port}"
|
|
proxies = {"http": proxy_url, "https": proxy_url}
|
|
|
|
resp = scraper.get(url, proxies=proxies, timeout=20)
|
|
|
|
if resp.status_code == 200:
|
|
match = re.search(r'Fraud\s*Score[:\s]*(\d+)', resp.text)
|
|
if match:
|
|
score = int(match.group(1))
|
|
return {"success": True, "ip": ip, "score": score}
|
|
else:
|
|
return {"success": False, "ip": ip, "error": "parse_failed"}
|
|
else:
|
|
return {"success": False, "ip": ip, "error": f"status_{resp.status_code}"}
|
|
except Exception as e:
|
|
return {"success": False, "ip": ip, "error": str(e)}
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print(json.dumps({"success": False, "error": "usage: check_fraud.py <ip> [proxy]"}))
|
|
sys.exit(1)
|
|
|
|
ip = sys.argv[1]
|
|
proxy = sys.argv[2] if len(sys.argv) > 2 else None
|
|
result = check_fraud(ip, proxy)
|
|
print(json.dumps(result, ensure_ascii=False))
|