Skip to content

Commit

Permalink
Update result.csv and ip.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
laityts committed Jan 5, 2025
1 parent d0e602c commit 0fb5345
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 278 deletions.
17 changes: 16 additions & 1 deletion cfip/ip.txt
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
104.18.1.153#US
104.18.5.24#HKG
104.18.239.191#CF优选
104.19.37.195#HKG
104.17.158.88#CF优选
104.18.94.128#HKG
104.17.123.250#CF优选
104.17.49.106#CF优选
104.18.70.105#HKG
172.67.151.129#SEA
104.16.64.74#CF优选
104.19.244.128#CF优选
104.18.247.178#CF优选
104.18.100.104#CF优选
104.16.21.247#CF优选
104.21.80.224#CF优选
104.17.113.42#CF优选
127 changes: 34 additions & 93 deletions cfst.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,95 +69,40 @@ def remove_file(file_path):
os.remove(file_path)
print(f"已删除 {file_path} 文件。")

def test_socks_proxy():
"""测试主 API 使用的 SOCKS 代理是否正常,并打印代理 IP"""
# 设置 SOCKS 代理
proxies = {
'http': 'socks5://eytan:[email protected]:15004',
'https': 'socks5://eytan:[email protected]:15004'
}
def get_colo(ip_address):
"""获取 IP 的 colo 信息,并写入日志文件"""
# 使用 Cloudflare 的 cdn-cgi/trace API
api_url = f'http://{ip_address}/cdn-cgi/trace'

try:
# 使用代理访问外部网站(例如 httpbin.org/ip)
response = requests.get('https://httpbin.org/ip', proxies=proxies, timeout=(5, 10))
if response.status_code == 200:
data = response.json()
print(f"SOCKS 代理正常工作,当前代理 IP: {data['origin']}")
return True
else:
print(f"SOCKS 代理请求失败,状态码: {response.status_code}")
return False
except requests.exceptions.RequestException as e:
print(f"SOCKS 代理请求出错: {e}")
return False

def get_country(ip_address):
"""获取 IP 的 country 信息和 proxyip 状态,并写入日志文件"""
# 主 API
api_url = f"https://proxyip.edtunnel.best/api?ip={ip_address}&host=speed.cloudflare.com&port={str(random_port)}&tls=true"

# 设置 SOCKS 代理
proxies = {
'http': 'socks5://eytan:[email protected]:15004',
'https': 'socks5://eytan:[email protected]:15004'
}

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'application/json',
'Accept': 'text/plain',
'Accept-Language': 'en-US,en;q=0.9',
}

try:
# 增加超时时间(连接超时 5 秒,读取超时 10 秒)
response = requests.get(api_url, headers=headers, proxies=proxies, timeout=(5, 10))
response = requests.get(api_url, headers=headers, timeout=(5, 10))
if response.status_code == 200:
data = response.json()
data = response.text
# 将完整的响应数据写入日志文件
with open(log_file, mode="a", encoding="utf-8") as log:
log.write(f"完整数据来自 {ip_address}:\n")
log.write(json.dumps(data, indent=4) + "\n\n")

# 提取国家代码
country = data.get('country', 'CF优选')

# 提取 proxyip 的值
proxyip = data.get('proxyip', False)
log.write(data + "\n\n")

# 打印 proxyip 的值
print(f"IP: {ip_address}, ProxyIP: {proxyip}")
# 解析 colo 信息
colo = "CF优选"
for line in data.splitlines():
if line.startswith("colo="):
colo = line.split("=")[1]
break

# 如果 proxyip 为 true,将 IP 写入 cfip/proxy.txt
if proxyip:
with open(proxy_txt, mode="a", encoding="utf-8") as proxy_file:
proxy_file.write(f"{ip_address}#{emoji}{country}{str(random_port)}\n")

# 返回 country
return f"{country}"
# 返回 colo
return f"{colo}"
else:
print(f"API 请求失败,IP {ip_address} 状态码: {response.status_code}")
print(f"API 请求失败,IP {ip_address} 状态码: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"主 API 请求出错,IP {ip_address}: {e}")

# 如果主 API 失败,尝试备用 API
backup_url = f'https://ipinfo.io/{ip_address}?token=fcadb7eaa35d6a'
try:
# 增加超时时间(连接超时 5 秒,读取超时 10 秒)
response = requests.get(backup_url, headers=headers, timeout=(5, 10))
if response.status_code == 200:
print(f"使用备用 API ,IP {ip_address}")
data = response.json()
# 将完整的响应数据写入日志文件
with open(log_file, mode="a", encoding="utf-8") as log:
log.write(f"完整数据来自 {ip_address}:\n")
log.write(json.dumps(data, indent=4) + "\n\n")
# 提取国家代码
country = data.get('country', 'CF优选')
return f"{country}"
else:
print(f"备用 API 请求失败,IP {ip_address} 状态码: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"备用 API 请求出错,IP {ip_address}: {e}")
print(f"API 请求出错,IP {ip_address}: {e}")

# 降低请求频率,每次请求后等待 1 秒
time.sleep(2)
Expand All @@ -169,10 +114,6 @@ def get_country(ip_address):
# 主程序逻辑
# ------------------------------

# 测试 SOCKS 代理
print("正在测试 SOCKS 代理...")
test_socks_proxy()

# 检查 cfst 文件是否存在
if not os.path.exists(cfst_path):
print(f"文件 {cfst_path} 不存在,正在执行安装和测试命令...")
Expand Down Expand Up @@ -224,37 +165,37 @@ def get_country(ip_address):
if len(ip_addresses) >= 20:
break

# 将 IP 地址和 country 信息写入 ip.txt
# 将 IP 地址和 colo 信息写入 ip.txt
with open(output_txt, mode="w", encoding="utf-8") as txtfile:
for ip, speed in zip(ip_addresses, download_speeds):
country = get_country(ip) # 接收 country 和 proxyip
txtfile.write(f"{ip}#{country}\n")
print(f"IP: {ip}, Country: {country}")
colo = get_colo(ip) # 接收 colo 和 proxyip
txtfile.write(f"{ip}#{colo}\n")
print(f"IP: {ip}, colo: {colo}")

print(f"提取的 IP 地址和 country 信息已保存到 {output_txt}")
print(f"提取的 IP 地址和 colo 信息已保存到 {output_txt}")

# 将 IP 地址、端口、country 信息和下载速度写入 ipport.txt
# 将 IP 地址、端口、colo 信息和下载速度写入 ipport.txt
with open(port_txt, mode="w", encoding="utf-8") as txtfile:
for ip, speed in zip(ip_addresses, download_speeds):
country = get_country(ip)
emoji = colo_emojis.get(country, "☁️") # 确保 colo_emojis 的键是 country
txtfile.write(f"{ip}:{str(random_port)}#{emoji}{country}┃⚡{speed}(MB/s)\n")
print(f"IP: {ip}, Port: {random_port}, Country: {emoji}{country}, Speed: {speed}")
colo = get_colo(ip)
emoji = colo_emojis.get(colo, "☁️") # 确保 colo_emojis 的键是 colo
txtfile.write(f"{ip}:{str(random_port)}#{emoji}{colo}┃⚡{speed}(MB/s)\n")
print(f"IP: {ip}, Port: {random_port}, colo: {emoji}{colo}, Speed: {speed}")

print(f"提取的 IP 地址、端口、country 信息和下载速度已保存到 {port_txt}")
print(f"提取的 IP 地址、端口、colo 信息和下载速度已保存到 {port_txt}")

remove_unreachable_ips(output_cf_txt, iplog_file)

# 筛选下载速度大于 10 MB/s 的 IP,并追加写入 ip.txt
with open(output_cf_txt, mode="a", encoding="utf-8") as cf_file:
for ip, speed in zip(ip_addresses, download_speeds):
if float(speed) > 10:
country = get_country(ip)
emoji = colo_emojis.get(country, "☁️") # 确保 colo_emojis 的键是 country
cf_file.write(f"{ip}:{str(random_port)}#{emoji}{country}┃⚡{speed}(MB/s)\n")
print(f"符合条件的 IP: {ip}, Port: {random_port}, Country: {emoji}{country}, Speed: {speed}")
colo = get_colo(ip)
emoji = colo_emojis.get(colo, "☁️") # 确保 colo_emojis 的键是 colo
cf_file.write(f"{ip}:{str(random_port)}#{emoji}{colo}┃⚡{speed}(MB/s)\n")
print(f"符合条件的 IP: {ip}, Port: {random_port}, colo: {emoji}{colo}, Speed: {speed}")

print(f"筛选出的 IP 地址、端口、country 信息和下载速度已追加到 {output_cf_txt}")
print(f"筛选出的 IP 地址、端口、colo 信息和下载速度已追加到 {output_cf_txt}")

# Git 上传步骤
try:
Expand Down
17 changes: 16 additions & 1 deletion csv/result.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
IP 地址,已发送,已接收,丢包率,平均延迟,下载速度 (MB/s)
104.18.1.153,4,4,0.00,56.89,3.62
104.18.5.24,4,4,0.00,61.72,0.00
104.18.239.191,4,4,0.00,94.68,0.00
104.19.37.195,4,4,0.00,128.00,0.00
104.17.158.88,4,4,0.00,137.52,0.00
104.18.94.128,4,4,0.00,140.89,0.00
104.17.123.250,4,4,0.00,143.21,0.00
104.17.49.106,4,4,0.00,154.38,0.00
104.18.70.105,4,4,0.00,197.62,0.00
172.67.151.129,4,4,0.00,199.89,0.00
104.16.64.74,4,4,0.00,204.61,0.00
104.19.244.128,4,4,0.00,206.02,0.00
104.18.247.178,4,4,0.00,207.62,0.00
104.18.100.104,4,4,0.00,207.97,0.00
104.16.21.247,4,4,0.00,210.58,0.00
104.21.80.224,4,4,0.00,211.01,0.00
104.17.113.42,4,4,0.00,222.76,0.00
31 changes: 11 additions & 20 deletions log/iplog.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
以下IP地址不通,已从文件中删除(检测时间: 2025-01-05 23:28:40.384297):
IP: 104.18.232.171, 端口: 2087
IP: 190.93.246.134, 端口: 2087
IP: 104.17.121.139, 端口: 2087
IP: 104.19.221.111, 端口: 2087
IP: 104.16.199.234, 端口: 2087
IP: 104.16.204.242, 端口: 2087
IP: 162.159.80.122, 端口: 2083
IP: 104.19.217.219, 端口: 2083
IP: 162.159.43.220, 端口: 2083
IP: 162.159.34.131, 端口: 2083
IP: 104.25.242.123, 端口: 2083
IP: 104.18.148.40, 端口: 2083
IP: 104.18.236.49, 端口: 2083
IP: 104.16.2.242, 端口: 2083
IP: 162.159.35.108, 端口: 2083
IP: 104.25.243.125, 端口: 2083
IP: 104.18.173.25, 端口: 2083
IP: 104.17.140.192, 端口: 2083
IP: 104.18.172.222, 端口: 2083
以下IP地址不通,已从文件中删除(检测时间: 2025-01-06 01:43:33.430361):
IP: 104.18.186.72, 端口: 2083
IP: 104.18.224.22, 端口: 2083
IP: 104.19.222.196, 端口: 2083
IP: 104.19.213.115, 端口: 2083
IP: 172.64.153.115, 端口: 2053
IP: 104.16.207.254, 端口: 2053
IP: 104.16.243.166, 端口: 2053
IP: 104.18.47.139, 端口: 2053
IP: 104.18.181.45, 端口: 2053
IP: 104.17.150.21, 端口: 2053
Loading

0 comments on commit 0fb5345

Please sign in to comment.