Every time you connect to a private network, may it be your college, office, school, etc. the captive portal screen appears where you have to enter your credentials provided by the organization. The idea is to automate that process so that whenever we are connected to any router in the same network, it automatically gets logged in.
Note: In the following article, the steps are provided which may not work for every network, but the idea is to understand the process, and it can be tried as most of the captive portals are loosely built, so it is worth a try.
System Requirement: Any Unix based system, preferably ubuntu Linux.
Step 1: Study of the captive portal page. This is one of the important steps and has to be carried out keenly. Right-Click on the text area provided and select inspect (Considering the browser being used is Chrome/Firefox). Notice the “name” field in the input text area. It must be something like ‘username’ or ‘password'(as shown in the image).
Note: Generally these codes will be in a single straight line, so hard to interpret. Hence any online beautifier can be used to format the code to make it more readable.
Signature means here the number of variables required, their sequence, etc. Sometimes some variables require timestamp, so a dummy value can be supplied to it(if required, the actual timestamp can also be used). Notice in the given image, the “mode” variable is given value as 191, which means login state and the value 193 which means logout state. This can be derived by reading the code keenly.
Query that was found for login:
queryString = “mode=191&username=” + encodeURIComponent(UserValue) + “&password=” + encodeURIComponent(document.frmHTTPClientLogin.password.value) + “&a=” + (new Date).getTime() + producttype;
Query that was found for logout:
queryString = “mode=193&username=” + encodeURIComponent(document.frmHTTPClientLogin.username.value) + “&a=” + (new Date).getTime() + producttype;
Step 4: Creation of own query string with the variables. Once the query is observed, it is easy to make the own query with the same variables and filling in the appropriate data accordingly. The link that was made in this case was as follows :
An important thing to be noted here is that one might think that this string can be appended to the IP of the captive portal and then used in browser. For example,
But it is important to note that this won’t work in all cases this can only work in the case where the backend technology like PHP was used where variable parsing using link is possible.
Step 5: Sending the POST request using the terminal. Once the POST request can be sent by the terminal in Linux, then it can be inserted in a bash script for automation. To send POST request here, a non-graphical browser was used made for Linux. There are many non-graphical browsers out there like lynx, w3m, etc. In this case, the w3m browser was used. It can be studied easily from the manual pages of Linux. The use of POST by w3m is well explained in its manual page (shown in the image).
w3m -post – http://192.168.1.8:8294/login.xml<<<'mode=191&username=admin&password=root&a=1551345153461'
Step 6: Inserting it into a bash script. To make the process automated, it is necessary to make a bash script file that will run every time you connect to the network of your organization. To make a simple bash script go to terminal and type
Nano is a command-line editor, which will now create a file named autologin. Now paste the following script in the editor, by pressing
Note: To create a bash file do not enter an extension to the filename as Linux never works on extension but identifies the files internally. Linux knows itself, whether the file is an ASCII text file, doc file or a bash file.
#!/bin/bash wget -q --tries=10 --timeout=10 http://192.168.1.8:8294 if [[ $? -eq 0 ]]; then w3m -post - http://192.168.1.8:8294/login.xml <<<'mode=191&username=admin&password=root&a=1551345153461' echo "Online!" else echo "Unreachable!" fi
- The first line of the code indicates that the file is a bash script, which is to be executed using bash only and the location of it is /bin/bash.
- wget is a Linux command, it is basically a program that is used to get content from the internet.
- Here, in this case, wget is used to check the connectivity of the PC to the network, the IP is checked that if it is active or not. If that IP is not active then that means that the device is not connected to the private network of the organization and the script won’t be executed further.
- The flags to wget are the number of tries to do before aborting, similarly for timeout. -q is used to turn off verbose.
- The $? is an environment variable that is used to store return values in Linux environment. If wget returns false, $? turns 0 and the control will go to else and nothing will happen.
- But when the IP is active, i.e. when wget will return a positive return value, it will be reflected in $? and the command w3m will be executed and the login will be done successfully.
Step 7: Making the script executable, every time it is connected to a network. This is the final part, where the script is to be made executable, every time it is connected to any network. It will internally find if the network is the private network of the organization or not and will log in accordingly. For this step, go to your
In this folder, there are 4 folders(as of the latest version of ubuntu-19.10) named:
if-up.d. The script just was written has to be pasted in the “
if-up.d” folder. Linux internally calls all the scripts present in this folder every time it is connected to a new network.
Note: If you don’t find the 4 folders by default, create the one we need and add the entry to the
/etc/network/interfaces file. To paste the script, go to the directory where the script is present, and type:
sudo cp autologin /etc/network/if-up.d
Step 8: Making the file executable and rebooting network. The ownership of the file must be changed to root. Hence type the command:
sudo chown root:root autologin
Then give the permissions to make the file executable:
sudo chmod +x autologin
Finally, restart the network manager for the new settings to take place!
This should make your PC able to login to the private network automatically, every time you connect it to the network! Although now you are logged in, the pop-up window of the captive portal may always occur for logging into the network, every time you connect to a network. To get rid of it, go to Settings->Privacy and turn the Connectivity Checking off.
- Automated Recursive Encryption in a Directory Using Shell Script
- How to add a Login Form to an Image using HTML and CSS ?
- How to create admin login page using PHP ?
- How to implement Facebook login in your Web app with Firebase ?
- How to implement Google Login in your Web app with Firebase ?
- Login form using Node.js and MongoDB
- How to change login screen background in Ubuntu
- HTML | Responsive Modal Login Form
- Difference Between Arch Linux and Kali Linux
- Linux Virtualization : Linux Containers (lxc)
- Why Linux is Better?
- Run Levels in Linux
- od command in Linux with example
- Permissions in Linux
- SED command in Linux | Set 2
- Some useful Linux Hacks
- who command in Linux
- du Command in LINUX
- 'dd' command in Linux
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.