0

My school network have a captive portal. Using Google Chrome's "copy as cURL" seems to log me in using curl, but I want to automate this process so it happens as soon as the mac connects to Wi-Fi. How would I achieve that? The curl command is as follows:

curl 'http://1.1.1.3/ac_portal/login.php' -H 'Connection: keep-alive' -H 'Accept: */*' -H 'Origin: http://1.1.1.3' -H 'X-Requested-With: XMLHttpRequest' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Mobile Safari/537.36' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Referer: http://1.1.1.3/ac_portal/20171018144956/pc.html?template=20171018144956&tabs=pwd&vlanid=0&url=http://www.gstatic.com/generate_204' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh' -H 'Cookie: ac_login_info=passwork; Sessionid=3566675246-1' --data 'opr=pwdLogin&userName=student&pwd=password&rememberPwd=1' --compressed --insecure

The network name is SCLSCHOOL_G, SCLSCHOOL_F, and SCLSCHOOL_H.

3 Answers 3

3

There’s nothing that allows you to kick off a script when you attach to a particular network, so you’ll have to use two tools

  • launchctl You’ll have to start the job based on network availability. Unfortunately, this only checks to see if you’re connected to any network, not a specific one.
  • networksetup that gets the current SSID you’re attached to. The command you will need is

    networksetup -listpreferredwirelessnetworks en1 | grep ${SSID} | cut -f2
    

Then in a bash script, compare the output of that command and if it matches the SSID you want, run the curl command.

2
  • Would you mind explaining how to use those two tools? I'm not familiar with using tools in a bash script.
    – Joy Jin
    Commented Jan 11, 2020 at 3:21
  • And I don't really mind executing the curl command for every network. My home network do not have a device that have the same ip so it doesn't really matter.
    – Joy Jin
    Commented Jan 11, 2020 at 3:24
0

You can also put it as a script for all apps and use Script Editor's menu bar button which sits close to Wi-Fi button. ~/Library/Scripts is the folder where the scripts are accessible to all apps.

https://apple.stackexchange.com/a/373438/313842

0

In the end, I used DSSW Power Manager to automate this process. I execute the curl command when I wake the macbook pro, and power off the Wifi when I sleep the macbook pro (in case it connects automatically), and specified the time range to be the time I'm in school. If anyone has the same problem and sometimes can't log in to the Wifi on first connect (curl will return error 7), my (fish) script is below:

while <curl command> 2>&1| grep \(7\) ; networksetup -setairportpower en0 on ; <curl command>; echo ; sleep 0.1 ; end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .