├── LICENSE ├── README.md └── authentication.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Ankur 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IITBHU Wifi Logger 2 | The current system has a firewall authentication system and this makes us enter the credentials again and again. We might have also lost our wifi network on curcial time due to this xD. In order to avoid the boring task and losing the network during important times, I created a shell script which currently suports Unix and Mac. I'm planning to make a cross platform GUI for the same so that it can work on other operating sytems as well. 3 | 4 | ## Prerequisite 5 | Make sure to install `net-tools` 6 | ``` 7 | sudo apt-get install net-tools 8 | ``` 9 | ## How to run the script 10 | > Note: Make sure to open the terminal in the project directory 11 | - First task is to make the script executable 12 | ``` 13 | chmod +x ./authentication.sh 14 | ``` 15 | - Execute the script with 16 | ``` 17 | bash authentication.sh 18 | ``` 19 | - Adding the script to crontab (so that the script runs after every reboot) 20 | 21 | For Linux: 22 | - `crontab -e` 23 | - Add this command to the opened file `@reboot `

24 | > ![Screenshot from 2023-01-04 11-43-38](https://user-images.githubusercontent.com/76884959/210495096-d4067e61-a09a-4e0e-b058-e2ecd9c83290.png) 25 | 26 | For Mac OS: 27 | - Follow this [link](https://stackoverflow.com/questions/6442364/running-script-upon-login-in-mac-os-x#:~:text=478-,Follow%20this%3A,-start%20Automator.app) to add the script on startup. 28 | 29 | And voila you've added an automated wifi login system in your device. 30 | 31 | --- 32 | If you found this project helpful, please give a ⭐ from your ♥. 33 | -------------------------------------------------------------------------------- /authentication.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | firewall_url="http://192.168.249.1:1000" 4 | username="" 5 | password="" 6 | 7 | pLength=${#password} 8 | 9 | if [[ "$OSTYPE" == "linux-gnu"* ]]; then 10 | interface="$(route | grep '^default' | grep -o '[^ ]*$')" 11 | elif [[ "$OSTYPE" == "darwin"* ]]; then 12 | interface="$(route -n get default | grep 'interface:' | grep -o '[^ ]*$')" 13 | else 14 | echo "Doesn't support your OS!" 15 | exit 1 16 | fi 17 | 18 | echo "$OSTYPE": "$interface" 19 | echo "Username: $username" 20 | echo -ne "Password:" 21 | for (( i=0; i<$pLength; i++ )); do 22 | echo -ne "*" 23 | done 24 | 25 | get_login_page() { 26 | local output="$(curl --silent \ 27 | --interface "${interface}" -k "${firewall_url}/logout?")" 28 | echo "${output}" | grep -oE '"htt[^"]*"' | grep -oE 'http[^"]*' 29 | } 30 | 31 | get_magic() { 32 | local login_page="${1}"; shift 33 | local output="$(curl --silent \ 34 | --interface "${interface}" -k "${login_page}")" 35 | local quoted="$(echo "${output}" | grep -oE \ 36 | '"magic" value="[^"]*"' | grep -oE '"[^"]*"$')" 37 | echo "${quoted}" | grep -oE '[^"]*' 38 | } 39 | 40 | do_login() { 41 | local magic="${1}"; shift 42 | local output="$(curl -k --interface "${interface}" -X POST --silent \ 43 | -d "username=${username}" \ 44 | -d "password=${password}" \ 45 | -d "magic=${magic}" \ 46 | -d "submit=Continue" \ 47 | "${firewall_url}/" )" 48 | echo "${output}" | grep -oE 'http[^"]*logout[^"]*' 49 | echo "${output}" | grep -oE 'http[^"]*keepalive[^"]*' 50 | } 51 | 52 | log_out() { 53 | local url="${1}"; shift 54 | curl -k --interface "${interface}" --silent "${url}" 55 | } 56 | 57 | keep_alive() { 58 | local url="${1}"; shift 59 | echo "Keepalive url is" "${url}" 60 | while :; do 61 | local output="$(curl -k -silent --interface "${interface}" "${url}")" 62 | 63 | if echo "${output}" | grep -q "leave it open"; then 64 | echo "Keepalive successful" 65 | sleep 10 66 | else 67 | echo "Keepalive unsuccessful; Trying to get login screen" 68 | break 69 | fi 70 | done 71 | } 72 | 73 | main() { 74 | local output="${1}"; shift 75 | logout_url=$(echo "$output" | head -1) 76 | keepalive_url=$(echo "$output" | tail -1) 77 | 78 | echo "${logout_url}" 79 | echo "${keepalive_url}" 80 | 81 | keep_alive "${keepalive_url}" 82 | } 83 | 84 | while :; do 85 | lpage="$(get_login_page)" 86 | magic="$(get_magic "${lpage}")" 87 | lurls="$(do_login "${magic}")" 88 | main "${lurls}" 89 | sleep 1 90 | done 91 | --------------------------------------------------------------------------------