在线使用:代理检测 (skyw.cc)
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$ip = $_POST['ip'];
$port = $_POST['port'];
$username = $_POST['username'] ?? null;
$password = $_POST['password'] ?? null;
$protocol = $_POST['protocol'];
$proxy = "$ip:$port";
$proxyAuth = $username ? "$username:$password" : null;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://4.ipw.cn");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 设置超时时间为10秒
// 根据协议类型设置代理类型
if ($protocol === 'socks5') {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
} elseif ($protocol === 'socks4') {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
}
if ($proxyAuth) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch); // 获取curl错误信息
if ($httpCode == 200) {
echo "代理检测成功,当前IP: " . $response;
} else {
echo "代理检测失败,错误代码: " . $httpCode . ",错误信息: " . $curlError;
}
curl_close($ch);
return;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>代理检测</title>
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1 class="mb-4">代理检测工具</h1>
<div class="mb-3">
<label for="proxyString" class="form-label">粘贴代理字符串</label>
<input type="text" class="form-control" id="proxyString" placeholder="">
</div>
<button id="importProxy" class="btn btn-secondary mb-3">一键导入</button>
<form id="proxyForm">
<div class="mb-3">
<label for="ip" class="form-label">IP地址</label>
<input type="text" class="form-control" id="ip" name="ip" required>
</div>
<div class="mb-3">
<label for="port" class="form-label">端口</label>
<input type="number" class="form-control" id="port" name="port" required>
</div>
<div class="mb-3">
<label for="username" class="form-label">用户名</label>
<input type="text" class="form-control" id="username" name="username">
</div>
<div class="mb-3">
<label for="password" class="form-label">密码</label>
<input type="text" class="form-control" id="password" name="password">
</div>
<div class="mb-3">
<label for="protocol" class="form-label">协议类型</label>
<select class="form-select" id="protocol" name="protocol" required>
<option value="http">HTTP</option>
<option value="socks4">SOCKS4</option>
<option value="socks5">SOCKS5</option>
</select>
</div>
<button type="submit" class="btn btn-primary">检测代理</button>
</form>
<div id="result" class="mt-4"></div>
</div>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js"></script>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/layer/3.5.1/layer.min.js"></script>
<script>
$(document).ready(function() {
$('#proxyForm').on('submit', function(e) {
e.preventDefault();
layer.load(2); // 显示加载动画
$.ajax({
url: 'check_proxy.php',
type: 'POST',
data: $(this).serialize(),
success: function(response) {
layer.closeAll('loading'); // 关闭加载动画
layer.msg(response, {icon: 1}); // 显示成功消息
$('#result').html('<div class="alert alert-info">' + response + '</div>');
},
error: function() {
layer.closeAll('loading'); // 关闭加载动画
layer.msg('检测失败,请重试。', {icon: 2}); // 显示错误消息
$('#result').html('<div class="alert alert-danger">检测失败,请重试。</div>');
}
});
});
$('#importProxy').on('click', function() {
const proxyString = $('#proxyString').val();
const regexWithAuth = /^(http|socks4|socks5):\/\/([^:]+):([^@]+)@([^:]+):(\d+)$/;
const regexWithoutAuth = /^(http|socks4|socks5):\/\/([^:]+):(\d+)$/;
let match = proxyString.match(regexWithAuth);
if (!match) {
match = proxyString.match(regexWithoutAuth);
}
if (match) {
const protocol = match[1];
const ip = match[match.length - 2];
const port = match[match.length - 1];
let username = '';
let password = '';
$('#protocol').val(protocol);
$('#ip').val(ip);
$('#port').val(port);
if (match.length == 6) {
username = match[2];
password = match[3];
$('#username').val(username);
$('#password').val(password);
}
} else {
alert('代理字符串格式不正确,请检查。');
}
});
});
</script>
</body>
</html>