How to Check a Checkbox on a Router Page with curl
This guide shows you how to use curl to send HTTP requests that toggle a checkbox on a router’s web interface, which is useful for automating settings changes or testing without a browser. You’ll learn to inspect the form, extract the necessary tokens, and submit the request correctly. No special tools are needed beyond curl and a terminal.
What You’ll Need
- A router with a web-based admin interface (most consumer routers).
- The router’s IP address (often 192.168.1.1 or 192.168.0.1).
- Administrator username and password for the router.
- curl installed on your computer (available by default on macOS and most Linux distributions; on Windows, use the curl.exe that ships with Windows 10/11 or install it).
- Basic familiarity with using a terminal or command prompt.
Step-by-Step
- Find the router’s login page and form details. Open a browser, go to your router’s IP address, and log in as you normally would. Right-click on the page and select “Inspect” (or press F12) to open developer tools. Go to the “Network” tab, then perform a login. Look at the request that is sent—typically a POST to a URL like
/login.cgior/cgi-bin/luci. Note the exact URL, the request method (usually POST), and the form field names (e.g.,username,password). - Log in with curl and save the session cookie. Most routers use cookie-based sessions. Use curl to send a login request and save the cookie jar to a file. For example, if the login URL is
http://192.168.1.1/login.cgiand fields areuserandpass, the command would be:curl -c cookies.txt -d "user=admin&pass=yourpassword" http://192.168.1.1/login.cgi
Replace the URL and field names with your router’s actual ones. The
-coption writes the cookies to a file. - Navigate to the page containing the checkbox. After logging in, you need to find the exact URL of the settings page that has the checkbox. In your browser, go to that page (e.g., Wireless Settings, Firewall, etc.). Look at the address bar and note the URL, like
http://192.168.1.1/wifi_adv.asp. - Inspect the form that contains the checkbox. On that page, use the browser’s developer tools to locate the checkbox element. Right-click on the checkbox and select “Inspect”. Look at its
nameattribute (e.g.,enable_wifi) and thevalueattribute (often “1” for checked, “0” for unchecked). Also note the form’sactionURL (the page that processes the form) and themethod(usually POST). - Check for CSRF tokens or hidden fields. Many routers include a hidden token (like
csrf_tokenorsession_id) in forms to prevent cross-site request forgery. Look for hidden inputs in the form. You’ll need to include these in your curl request. You can get them by downloading the page with curl and parsing the HTML, or you can manually copy them from the browser’s developer tools. - Send the request with curl to check the checkbox. To check the box, you send a POST request to the form’s action URL, including all the necessary fields. The checkbox field should be set to its “checked” value (usually “1”). For example:
curl -b cookies.txt -d "enable_wifi=1&csrf_token=abc123" http://192.168.1.1/wifi_adv.asp
Use
-b cookies.txtto send the session cookie. Include all other required fields from the form (like other checkboxes or text inputs) to avoid resetting them. - Verify the change. After sending the request, you can reload the settings page in your browser or use curl to fetch the page and check if the checkbox is now checked (look for
checkedattribute in the HTML). Some routers may require a reboot or a separate “Save” button—if the change doesn’t stick, check if there’s an additional “apply” or “save” step.
Common Mistakes
- Not including the CSRF token: Many routers reject requests without a valid token. Always include it.
- Using GET instead of POST: Most form submissions use POST. Using GET might just load the page without changing anything.
- Forgetting to send cookies: Without the session cookie, the router will redirect you to the login page.
- Setting the wrong value: Some checkboxes use “on” or “true” instead of “1”. Check the HTML source to see the exact value.
- Omitting other form fields: If you only send the checkbox field, the router may interpret missing fields as “unchecked” and reset them. Always send the entire form.
Tips
- Use the
-vflag with curl to see the HTTP headers and response, which helps debug issues. - If the router uses HTTPS, add
-kto skip certificate verification (only for testing). - To uncheck a checkbox, simply send the field with an empty value or omit it, depending on the router’s logic. Test to see what works.
- Write a shell script to automate the process, storing the cookie file and using variables for the IP and credentials.
- Check the router’s manual or online documentation for specific API endpoints—some routers have a REST API that is easier to use.
Troubleshooting
- Getting redirected to login page: Your session may have expired. Log in again with curl and update the cookies file.
- 403 Forbidden error: This usually means the CSRF token is missing or invalid. Re-fetch the page to get a fresh token.
- Checkbox doesn’t change: The router may require a “Save” or “Apply” action after the POST. Look for a separate URL or a button that triggers the save.
- Changes revert after reboot: Some settings are stored in volatile memory. You may need to save the configuration to NVRAM or flash memory—check the router’s interface for a “Save” or “Persist” option.
- curl command not found: Install curl using your package manager (e.g.,
apt install curlon Debian/Ubuntu,brew install curlon macOS). - Router uses JavaScript to submit the form: Some modern routers use AJAX. In that case, inspect the network requests in the browser to see the exact API endpoint and payload, then replicate that with curl.
Frequently Asked Questions
Q: Can I use curl to check a checkbox without logging in?
A: No, most routers require authentication. You must log in first to get a session cookie.
Q: How do I find the CSRF token?
A: Use curl to fetch the page and search for csrf in the HTML, or use your browser’s developer tools to inspect the form’s hidden inputs.
Q: What if the router uses HTTPS with a self-signed certificate?
A: Use the -k flag to ignore certificate errors, but be aware that this is insecure for production use.
Q: Can I use this method for any router?
A: The general approach works for most routers, but the exact URLs, field names, and tokens vary. You must inspect each router’s interface.
Q: Is it safe to automate router settings with curl?
A: Yes, if you are careful. Always test on a non-critical setting first, and make sure you have a backup of your configuration.
Q: What if the checkbox is part of a multi-step wizard?
A: You may need to send multiple requests in sequence, mimicking the wizard’s steps. Inspect the network traffic to see the sequence.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.