观察到自动重定向到登录页面
在此步骤中,你将看到强制门户 (captive portal) 的实际运行情况。连接到带有强制门户的网络后,任何浏览网页的尝试通常都会被拦截并重定向到登录页面或服务条款页面。
我们将通过使用 curl 命令尝试访问一个网站来模拟这一点。由于我们模拟的网络环境由我们刚刚启动的 Python 服务器控制,因此对 localhost:8000 的任何 HTTP 请求都将被“捕获”并提供我们门户中的 index.html 文件。
使用 curl 向本地服务器发出请求。这模仿了连接到新网络后浏览器发出的初始请求。
curl http://localhost:8000
该命令将返回伪造登录页面的 HTML 源代码。在真实的浏览器中,此代码将被渲染为图形登录表单。
<!DOCTYPE html>
<html>
<head>
<title>CorpWifi Login</title>
<style>
body {
font-family: sans-serif;
background: #f0f2f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.login-box {
background: white;
padding: 20px 40px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
text-align: center;
}
input {
margin: 10px 0;
padding: 8px;
width: 200px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 10px 20px;
background-color: #1877f2;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
width: 100%;
}
</style>
</head>
<body>
<div class="login-box">
<h2>CorpWifi Access</h2>
<p>Please log in to continue.</p>
<input type="text" placeholder="Username" />
<br />
<input type="password" placeholder="Password" />
<br />
<button>Log In</button>
<p style="font-size: 12px; color: #888; margin-top: 15px;">
Powered by CorpWifi-Login.net
</p>
</div>
</body>
</html>