本文目录导读:

使用 curl(命令行)
# 只获取状态码
curl -s -o /dev/null -w "%{http_code}" https://example.com
# 更详细的输出
curl -I https://example.com 2>/dev/null | head -n 1
Python 脚本
import requests
from urllib.request import urlopen
import urllib.error
# 方法1:使用 requests 库
def get_status_code_requests(url):
try:
response = requests.get(url, timeout=5)
return response.status_code
except requests.exceptions.RequestException as e:
return f"Error: {e}"
# 方法2:使用 urllib
def get_status_code_urllib(url):
try:
conn = urlopen(url, timeout=5)
return conn.getcode()
except urllib.error.HTTPError as e:
return e.code
except urllib.error.URLError as e:
return f"Error: {e.reason}"
# 批量检测
urls = [
"https://www.google.com",
"https://www.github.com",
"https://www.nonexistent.com"
]
for url in urls:
status = get_status_code_requests(url)
print(f"{url}: {status}")
Node.js 脚本
const https = require('https');
const http = require('http');
// 获取状态码
function getStatusCode(url) {
return new Promise((resolve, reject) => {
const protocol = url.startsWith('https') ? https : http;
protocol.get(url, (response) => {
resolve(response.statusCode);
}).on('error', (err) => {
reject(err.message);
});
});
}
// 使用 async/await
async function checkUrls() {
const urls = [
'https://www.google.com',
'https://www.github.com'
];
for (const url of urls) {
try {
const status = await getStatusCode(url);
console.log(`${url}: ${status}`);
} catch (error) {
console.log(`${url}: Error - ${error}`);
}
}
}
checkUrls();
Bash 脚本(批量检测)
#!/bin/bash
# 检查单个URL
check_url() {
local url=$1
local status=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "$url")
echo "$url -> $status"
}
# 批量检查
urls=(
"https://www.google.com"
"https://www.github.com"
"https://www.nonexistent.com"
)
for url in "${urls[@]}"; do
check_url "$url"
done
PowerShell 脚本(Windows)
# 检查单个URL
function Get-StatusCode {
param($url)
try {
$response = Invoke-WebRequest -Uri $url -Method Head -TimeoutSec 5
return $response.StatusCode
}
catch {
if ($_.Exception.Response) {
return $_.Exception.Response.StatusCode.value__
}
return "Error: $($_.Exception.Message)"
}
}
# 批量检查
$urls = @(
"https://www.google.com",
"https://www.github.com"
)
foreach ($url in $urls) {
$status = Get-StatusCode $url
Write-Host "$url : $status"
}
快速在线检测(使用 curl 一行命令)
# 检测单个
curl -s -o /dev/null -w "%{http_code}" URL
# 检测多个并输出
for url in https://google.com https://github.com; do
echo "$url: $(curl -s -o /dev/null -w '%{http_code}' $url)"
done
注意事项
-
常用状态码:
- 200:成功
- 301/302:重定向
- 403:禁止访问
- 404:未找到
- 500:服务器错误
- 503:服务不可用
-
超时设置:建议设置超时时间,避免脚本卡住
-
错误处理:考虑网络问题、DNS解析失败等情况
-
请求限制:大量请求时注意添加延迟,避免被封IP
最简单的方案是使用 curl 命令,一行代码就能获取状态码,如果需要编程集成,Python 的 requests 库最为方便。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播