Skip to main content
added 147 characters in body
Source Link

With some help using AppleScript, Lynx, Fakeapp/Safari, and ControlPlane, My MacBook now always connected to captive portal automatically in my office. It still not an efficient way to make it, but it still get the job done perfectly. I hope someone can make it simpler.

Here's the code:

  1. Make sure we are in correct SSID

     do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
    
  2. Check captive portal address existence

     try
         do shell script ("ping -c 2 " & CaptiveAddress) -- set your captive address here
         set CaptiveExist to "yes"
     on error
         set CaptiveExist to "no"
     end try
    
  3. Test portal connection

     try
         set PortalOpened to do shell script ("/usr/local/bin/lynx --dump http://www.apple.com/library/test/success.html | grep 'Success'")
         if PortalOpened is "   Success" then
             set PortalOpened to "yes"
         else
             set PortalOpened to "no"
         end if
     on error
         set PortalOpened to "no"        
     end try
    
  4. Logging in to portal

     tell application "Fake"
         load URL "http://YourPortalAddress.html" -- put your captive address here
         set value of element with name "username" to "user"
         set value of element with name "password" in form with name "password" to "password"
         click element with id "logincaption"
     end tell
    
  5. Save those scripts as one application. Then use ControlPlane rules to make it run when triggered with specified SSID.

Surely login form on captive may have another HTML elements. You can add some display dialogdialogs or notifications, another nice stuffs to the scriptsdifferent SSID with it's own HTML elements and username/password. Fake is a browser+automator, so it will make life easier.

Don't forget to disable captive login popup. Now your Mac 100% autoconnect to the portal.

Hope that helps.

With some help using AppleScript, Lynx, Fakeapp/Safari, and ControlPlane, My MacBook now always connected to captive portal automatically in my office. It still not an efficient way to make it, but it still get the job done perfectly. I hope someone can make it simpler.

Here's the code:

  1. Make sure we are in correct SSID

     do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
    
  2. Check captive portal address existence

     try
         do shell script ("ping -c 2 " & CaptiveAddress) -- set your captive address here
         set CaptiveExist to "yes"
     on error
         set CaptiveExist to "no"
     end try
    
  3. Test portal connection

     try
         set PortalOpened to do shell script ("/usr/local/bin/lynx --dump http://www.apple.com/library/test/success.html | grep 'Success'")
         if PortalOpened is "   Success" then
             set PortalOpened to "yes"
         else
             set PortalOpened to "no"
         end if
     on error
         set PortalOpened to "no"        
     end try
    
  4. Logging in to portal

     tell application "Fake"
         load URL "http://YourPortalAddress.html" -- put your captive address here
         set value of element with name "username" to "user"
         set value of element with name "password" in form with name "password" to "password"
         click element with id "logincaption"
     end tell
    
  5. Save those scripts as one application. Then use ControlPlane rules to make it run when triggered with specified SSID.

Surely login form on captive may have another HTML elements. You can add some display dialog or another nice stuffs to the scripts. Fake is a browser+automator, so it will make life easier.

Hope that helps.

With some help using AppleScript, Lynx, Fakeapp/Safari, and ControlPlane, My MacBook now always connected to captive portal automatically in my office. It still not an efficient way to make it, but it still get the job done perfectly. I hope someone can make it simpler.

Here's the code:

  1. Make sure we are in correct SSID

     do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
    
  2. Check captive portal address existence

     try
         do shell script ("ping -c 2 " & CaptiveAddress) -- set your captive address here
         set CaptiveExist to "yes"
     on error
         set CaptiveExist to "no"
     end try
    
  3. Test portal connection

     try
         set PortalOpened to do shell script ("/usr/local/bin/lynx --dump http://www.apple.com/library/test/success.html | grep 'Success'")
         if PortalOpened is "   Success" then
             set PortalOpened to "yes"
         else
             set PortalOpened to "no"
         end if
     on error
         set PortalOpened to "no"        
     end try
    
  4. Logging in to portal

     tell application "Fake"
         load URL "http://YourPortalAddress.html" -- put your captive address here
         set value of element with name "username" to "user"
         set value of element with name "password" in form with name "password" to "password"
         click element with id "logincaption"
     end tell
    
  5. Save those scripts as one application. Then use ControlPlane rules to make it run when triggered with specified SSID.

Surely login form on captive may have another HTML elements. You can add some display dialogs or notifications, another different SSID with it's own HTML elements and username/password. Fake is a browser+automator, so it will make life easier.

Don't forget to disable captive login popup. Now your Mac 100% autoconnect to the portal.

Hope that helps.

Source Link

With some help using AppleScript, Lynx, Fakeapp/Safari, and ControlPlane, My MacBook now always connected to captive portal automatically in my office. It still not an efficient way to make it, but it still get the job done perfectly. I hope someone can make it simpler.

Here's the code:

  1. Make sure we are in correct SSID

     do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
    
  2. Check captive portal address existence

     try
         do shell script ("ping -c 2 " & CaptiveAddress) -- set your captive address here
         set CaptiveExist to "yes"
     on error
         set CaptiveExist to "no"
     end try
    
  3. Test portal connection

     try
         set PortalOpened to do shell script ("/usr/local/bin/lynx --dump http://www.apple.com/library/test/success.html | grep 'Success'")
         if PortalOpened is "   Success" then
             set PortalOpened to "yes"
         else
             set PortalOpened to "no"
         end if
     on error
         set PortalOpened to "no"        
     end try
    
  4. Logging in to portal

     tell application "Fake"
         load URL "http://YourPortalAddress.html" -- put your captive address here
         set value of element with name "username" to "user"
         set value of element with name "password" in form with name "password" to "password"
         click element with id "logincaption"
     end tell
    
  5. Save those scripts as one application. Then use ControlPlane rules to make it run when triggered with specified SSID.

Surely login form on captive may have another HTML elements. You can add some display dialog or another nice stuffs to the scripts. Fake is a browser+automator, so it will make life easier.

Hope that helps.