Skip to content

Instantly share code, notes, and snippets.

@ChaosO9
Forked from muhajirinlpu/login.sh
Last active August 4, 2025 06:53
Show Gist options
  • Select an option

  • Save ChaosO9/61cea173a8d3ddfffe17d6e7111a8252 to your computer and use it in GitHub Desktop.

Select an option

Save ChaosO9/61cea173a8d3ddfffe17d6e7111a8252 to your computer and use it in GitHub Desktop.
pens autologin

PENS Portal Autologin

This tutorial is assume you're using latest LTS Ubuntu and using IAC3 as the main URI to login. You can change the script manually to use your main PENS IAC Network URI captive portal.

Preparation

1. Account

Prepare your email and password, and make sure your account is active by manually login into PENS CAS portal. In this tutorial I will use this account below as an example

Email    : irfan@it.student.pens.ac.id
Password : irfan123

2. Prepare file

Download file login.sh and change

AUTH_USER="yourpensemail@it.student.pens.ac.id"
AUTH_PASS="yourpassword"

into your own account

AUTH_USER="irfan@it.student.pens.ac.id"
AUTH_PASS="irfan123"

(IMPORTANT) Change to your main IAC URI. Some PENS network have different IAC URI depends on how you connect to PENS network. For example:

IAC_URI="https://iac2.pens.ac.id:8003/index.php?zone=eepiswlan"

Save login.sh in your home directory ~/.pens/login.sh then add execution permission into login.sh file For example if you want to use command one by one

mkdir -p ~/.pens/login.sh
mv login.sh ~/.pens/login.sh
chmod +x  ~/.pens/login.sh

Testing

  1. Logout your current session account by accessing this link or your main IAC URI. and click button Disconnect. Or you can send "/clear_iac" message to PENS Bot Telegram
  2. Run your script in your terminal bash ~/.pens/login.sh, it should print text Internet not accessible. Logging into CAS portals...
  3. Check your internet connection, and make sure it's works

Finishing

1. Check Cron

Run sudo systemctl status cron.service and make sure the result is active and enabled

● cron.service - Regular background program processing daemon
     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-09-20 12:27:35 UTC; 6 days ago
       Docs: man:cron(8)
   Main PID: 3868188 (cron)
      Tasks: 1 (limit: 2220)
     Memory: 7.2M
        CPU: 57.421s
     CGroup: /system.slice/cron.service
             └─3868188 /usr/sbin/cron -f -P

if not, run sudo systemctl enable --now cron.service

2. Add file to cron file

Run crontab -e (if there is an interactive choice, just choose anything you want). The cron will execute the script every 15 minutes. Add this line in the bottom of text

*/15 * * * * /bin/bash /home/<your username>/.pens/login.sh

If you're confuse what <your username> is, just run whoami

#!/bin/bash
# =======================
# Your PENS Credentials and IAC URI
# =======================
AUTH_USER="yourpensemail@it.student.pens.ac.id"
AUTH_PASS="yourpassword"
IAC_URI="https://iac3.pens.ac.id:8007/index.php?zone=labpa"
# =======================
# Use full paths
# =======================
CURL=/usr/bin/curl
GREP=/usr/bin/grep
DATE=/usr/bin/date
# =======================
# Check if internet is accessible via IAC3
# =======================
$CURL -s "$IAC_URI" \
--header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0' \
--header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
--insecure | $GREP 'value="Disconnect"' > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "$($DATE) Internet not accessible. Logging into CAS portals..."
# =======================
# Login to IAC3 (labpa zone)
# =======================
$CURL --location "$IAC_URI" \
--header 'sec-ch-ua: "Not)A;Brand";v="8", "Chromium";v="138", "Microsoft Edge";v="138"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "Windows"' \
--header 'DNT: 1' \
--header 'Upgrade-Insecure-Requests: 1' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0' \
--header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
--header 'Sec-Fetch-Site: same-origin' \
--header 'Sec-Fetch-Mode: navigate' \
--header 'Sec-Fetch-User: ?1' \
--header 'Sec-Fetch-Dest: document' \
--cookie-jar /tmp/cookies.txt \
--cookie /tmp/cookies.txt \
--data-urlencode 'accept=Login' \
--data-urlencode "auth_pass=$AUTH_PASS" \
--data-urlencode "auth_user=$AUTH_USER" \
--data-urlencode 'redirurl=' \
--insecure > /dev/null
echo "$($DATE) Logged into IAC3"
else
echo "$($DATE) Internet already accessible through IAC3"
fi
@widiarrohman1234
Copy link

Thanks for your information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment