46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
|
#!/usr/bin/env python3
|
||
|
"""
|
||
|
快速网络连接测试脚本
|
||
|
"""
|
||
|
|
||
|
import socket
|
||
|
import time
|
||
|
import requests
|
||
|
|
||
|
def quick_test():
|
||
|
target_url = "https://ac.bit.edu.cn"
|
||
|
target_host = "ac.bit.edu.cn"
|
||
|
|
||
|
print("快速网络连接测试")
|
||
|
print("=" * 40)
|
||
|
|
||
|
# DNS测试
|
||
|
print("1. DNS解析测试...")
|
||
|
try:
|
||
|
ip = socket.gethostbyname(target_host)
|
||
|
print(f" 成功: {target_host} -> {ip}")
|
||
|
except Exception as e:
|
||
|
print(f" 失败: {e}")
|
||
|
return
|
||
|
|
||
|
# HTTP测试
|
||
|
print("\n2. HTTP请求测试...")
|
||
|
try:
|
||
|
start = time.time()
|
||
|
response = requests.get(
|
||
|
target_url,
|
||
|
timeout=(30, 90),
|
||
|
verify=False,
|
||
|
headers={'User-Agent': 'Mozilla/5.0'}
|
||
|
)
|
||
|
duration = time.time() - start
|
||
|
print(f" 成功: {response.status_code} ({duration:.2f}秒)")
|
||
|
except requests.exceptions.Timeout:
|
||
|
print(" 超时: 网络延迟过高")
|
||
|
except Exception as e:
|
||
|
print(f" 失败: {e}")
|
||
|
|
||
|
print("\n测试完成")
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
quick_test()
|