macOS 上如何为需要弹出独立 web 认证页面的 wifi 记住密码?

2016-06-16 23:41:40 +08:00
 appstore54321

连接 wifi 后会弹出一个独立窗口,地址是 captive.apple.com ,这里不像 safari 可以自动填充密码,每次都要手动输入很累,有办法记住密码吗? 除此之外还有个想法,可以分析服务器接口,写个脚本自动发送账户密码吗?

3147 次点击
所在节点    macOS
8 条回复
zander
2016-06-17 00:18:12 +08:00
https://support.apple.com/en-us/HT204497
Turn Auto-Join off if you don't want to connect automatically. Turn Auto-Login off to skip the Welcome screen the next time you connect to the network.
记不住是服务器设置问题,不让你自动登。
hxsf
2016-06-17 00:48:05 +08:00
@zander 这段话是 开关 1 控制 “是否自动连接这个 wifi ”, 开关二控制 “是否自动弹出登录窗口(如果需要登录)”
哪里来的服务器设置
hxsf
2016-06-17 00:50:50 +08:00
当然可以写个脚本。

关掉自动弹出的登录窗口,打开 chrome ,随便打开个 url , 302 到登录界面,打开 chrome 调试器的 network ,输入账号密码登录, devtool 里看发生了啥。然后根据这个写个 curl 命令就行。

我之前干过,环境是锐捷的 web 认证。
pH
2016-06-17 08:08:05 +08:00
@hxsf 愿闻其详啊,我这也是学校的认证,虽然是锐捷,但是好像学校封了一层, h3c 的路由
hxsf
2016-06-17 08:14:08 +08:00
r#4 @pH 浏览器里的登录界面,填完后会发送请求,我们要做的就是用程序模拟浏览器发出的请求呀
appstore54321
2016-06-17 13:38:21 +08:00
@hxsf
这是我在 chrome 里看到的 portal.js 的一部分:
$("form#loginForm").submit(function() { // loginForm is submitted
var username = $('#username').val(); // get username
var password = $('#password').val(); // get password

if (username && password) { // values are not empty
$.ajax({
type: "POST",
url: "login.php", // URL of the PHP script
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
// send username and password as parameters to the Perl script
data: {username:username, password:password},
// script call was *not* successful
error: function(XMLHttpRequest, textStatus, errorThrown) {
/*$('div#loginResult').text("responseText: " + XMLHttpRequest.responseText
+ ", textStatus: " + textStatus
+ ", errorThrown: " + errorThrown);*/
$('div#loginResult').text("Internal Error, Login Failed!");
$('div#loginResult').addClass("error");
}
,succes:
})}
是不是这样的代码就可以实现所需的功能?
curl -H "Content-Type: application/json" -X POST -d '{"username":"123","password":"abc"}' login.php
如果认证页面是 https 的,这样明文发送密码也可以吧...
hxsf
2016-06-17 21:28:05 +08:00
r#6 @appstore54321 右击 post 的那条 request ,选复制成 curl ,如图。



看看里面有没有什么是变量,然后写到 shell 脚本里就好。

其他语言脚本的话。照着 post 传递的数据自己写就好了。
appstore54321
2016-06-18 23:07:14 +08:00
@hxsf 感谢回复,这个方法很方便,学习到了。我已经把 curl 命令保存成一个 sh 文件,添加到开机启动项里就可以自动登录了,但是发现每次打开 wifi 登录界面自动弹出的情况下,浏览器和终端是连接不到网络的,没有办法登录,只有手动关闭窗口才能正常登录,而且至少要关两次,所以我搜索到了这个问题 http://apple.stackexchange.com/questions/45418/how-to-automatically-login-to-captive-portals-on-os-x (其实早就该自己 Google ,很惭愧),答案提到这个命令
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -boolean false
就可以禁止自动弹出登录页面了,这个问题应该算是解决了。
还有一个问题,有可以代替手工关掉这个窗口的脚本命令吗?或者是检测这个窗口是否处于打开的状态? AppleScript 似乎可以关闭某个程序的窗口,但是这个窗口属于哪个程序吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/286310

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX