mirror of
https://github.com/Stone-Red-Code/HotspotAutoLogin.git
synced 2026-11-02 07:18:02 +01:00
Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab2f468230 | ||
|
|
61dedb8592 | ||
|
|
9c70bf1480 | ||
|
|
40fda390bb | ||
|
|
f22d91d733 | ||
|
|
89fd7ee615 | ||
|
|
f17a881e86 | ||
|
|
3ff98344a1 | ||
|
|
0a4d2770d0 | ||
|
|
c92106848c | ||
|
|
2a53bd901c | ||
|
|
47db815aa9 | ||
|
|
8063974ad7 | ||
|
|
9498d65209 | ||
|
|
cb57c822c8 | ||
|
|
f5e94e0527 | ||
|
|
7094378fc7 | ||
|
|
88f2a82d43 |
+42
-32
@@ -1,15 +1,23 @@
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
import time
|
||||
import subprocess
|
||||
import pystray
|
||||
from PIL import Image
|
||||
import threading
|
||||
import tkinter as tk
|
||||
from PIL import Image
|
||||
from collections import deque
|
||||
from datetime import datetime
|
||||
import os
|
||||
import socket
|
||||
from urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += 'HIGH:!DH:!aNULL'
|
||||
|
||||
try:
|
||||
requests.packages.urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST += 'HIGH:!DH:!aNULL'
|
||||
except AttributeError:
|
||||
# no pyopenssl support used / needed / available
|
||||
pass
|
||||
|
||||
# Load configuration from file
|
||||
with open("config.json", "r") as f:
|
||||
@@ -24,11 +32,11 @@ expected_ssid = config["ssid"].lower()
|
||||
|
||||
def is_internet_available():
|
||||
try:
|
||||
# Attempt to resolve a common internet domain (e.g., google.com)
|
||||
host = socket.gethostbyname("www.google.com")
|
||||
# If successful, it means the internet is available
|
||||
return True
|
||||
except socket.error:
|
||||
# Try to send a simple HTTP GET request to a known website
|
||||
response = requests.get("https://www.google.com")
|
||||
# If the request was successful, it means the internet is available
|
||||
return response.status_code == 200
|
||||
except requests.ConnectionError:
|
||||
# If an exception is raised, there's no internet connectivity
|
||||
return False
|
||||
|
||||
@@ -48,7 +56,9 @@ def get_connected_wifi_ssid():
|
||||
return None
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json;charset=UTF-8",
|
||||
"Connection": "keep-alive",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
|
||||
}
|
||||
|
||||
# Function to add a message to the log file (txt)
|
||||
@@ -137,7 +147,7 @@ def create_system_tray_icon():
|
||||
pystray.MenuItem('Show Log', show_log_dialog),
|
||||
pystray.MenuItem('Exit', exit_application)
|
||||
)
|
||||
icon = pystray.Icon("my_icon", image, "WIFI Autologin", menu)
|
||||
icon = pystray.Icon("my_icon", image, "HotspotAutoLogin", menu)
|
||||
icon.run()
|
||||
|
||||
# Function to check network status
|
||||
@@ -150,46 +160,46 @@ def check_network_status():
|
||||
if is_internet_available():
|
||||
errorcount = 0
|
||||
sleepcount = config["check_every_second"]
|
||||
message = "Connected to "+config["ssid"]+" and internet connection is available. Checking again in "+str(sleepcount)+" seconds..."
|
||||
message = "Connected to " + config["ssid"] + " and internet connection is available. Checking again in " + str(sleepcount) + " seconds..."
|
||||
add_to_log(message)
|
||||
else:
|
||||
message = "Connected to "+config["ssid"]+", but internet connection is down. Running the script..."
|
||||
message = "Connected to " + config["ssid"] + ", but internet connection is down. Running the script..."
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
|
||||
# Semd the request and ignore SSL errors
|
||||
# Send the request and handle potential errors
|
||||
try:
|
||||
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False)
|
||||
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False, timeout=10, allow_redirects=True)
|
||||
|
||||
# Check the response status code
|
||||
if response.status_code == 200:
|
||||
# Success!
|
||||
errorcount = 0
|
||||
sleepcount = config["check_every_second"]
|
||||
message = "Request was successful. Connection established! Checking again in " + str(sleepcount) + " seconds..."
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
else:
|
||||
errorcount += 1
|
||||
sleepcount = 10 # Sleep ... seconds before trying again
|
||||
message = "Request failed with status code: {}. Trying again in {} seconds... (Errors: {}/10)".format(response.status_code, sleepcount, errorcount)
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
except requests.exceptions.RequestException as e:
|
||||
# Catch the exception and add a delay before trying again
|
||||
errorcount += 1
|
||||
sleepcount = 10
|
||||
message = "Failed to send request: {e}".format(e=e)+" Trying again in "+str(sleepcount)+" seconds... (Errors: "+str(errorcount)+"/10)"
|
||||
message = "Failed to send request: {}. Trying again in {} seconds... (Errors: {}/10)".format(e, sleepcount, errorcount)
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
time.sleep(sleepcount)
|
||||
continue
|
||||
|
||||
# Check the response status code
|
||||
if response.status_code == 200:
|
||||
# Success!
|
||||
errorcount = 0
|
||||
sleepcount = config["check_every_second"]
|
||||
message = "Request was successful. Connection established! Checking again in "+str(sleepcount)+" seconds..."
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
else:
|
||||
errorcount += 1
|
||||
sleepcount = 10 # Sleep ... seconds before trying again
|
||||
message = "Request failed with status code: {}".format(response.status_code)+" Trying again in "+str(sleepcount)+" seconds... (Errors: "+str(errorcount)+"/10)"
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
else:
|
||||
errorcount += 1
|
||||
sleepcount = 10 # Sleep ... seconds before trying again
|
||||
message = "Not connected to "+config["ssid"]+" Checking again in "+str(sleepcount)+" seconds... (Errors: "+str(errorcount)+"/10)"
|
||||
message = "Not connected to {}. Checking again in {} seconds...".format(config["ssid"], sleepcount)
|
||||
add_to_log(message)
|
||||
save_to_file(message)
|
||||
time.sleep(sleepcount)
|
||||
|
||||
time.sleep(sleepcount) # Sleep ... seconds before trying again
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
# HotspotAutoLogin Wi-Fi / Hotspot Autologin Script (Automate WEB Logins)
|
||||
HotspotAutoLogin is a Python script designed to automate the login process for public Wi-Fi or hotspot networks that require web-based authentication. This script is intended for situations where you often connect to networks that require a web login, such as public hotspots in cafes, hotels, or airports. The script continuously monitors your network connection and automatically logs you in when necessary.
|
||||
# HotspotAutoLogin Wi-Fi/Hotspot Autologin Script (Automate WEB Logins)
|
||||
|
||||

|
||||
|
||||
HotspotAutoLogin is a script that designed to automate the login process for Wi-Fi or hotspot networks that require web-based authentication. This script is intended for situations where you often connect to networks that require a web login, such as public hotspots in cafes, hotels, or airports. The script continuously monitors your network connection and automatically logs you in when necessary.
|
||||
|
||||
> # [Download the Latest Executable (.exe) Release](https://github.com/denizsafak/HotspotAutoLogin/releases/latest)
|
||||
> You can download the executable (.exe) version of the same script, making it easy to use without the need to install Python or other libraries.
|
||||
|
||||
## `How It Works`
|
||||
### Network Monitoring
|
||||
The script will continuously monitor your network connection. When you connect to the specified SSID but there is no internet access, it will attempt to log in automatically.
|
||||
|
||||
### Auto Login
|
||||
If you are connected to the correct SSID but lack internet access, the script attempts to log in by sending an HTTP POST request to the provided URL with the specified credentials. If the login is successful (HTTP status code 200), the script will continue monitoring.
|
||||
### Autologin
|
||||
If you are connected to the correct SSID but lack internet access, the script attempts to log in by sending an POST request to the provided URL with the specified credentials. If the login is successful (status code 200), the script will continue monitoring.
|
||||
|
||||
### Logging
|
||||
Any important events or actions taken by the script are logged both in a log file (log.txt) and in the log window that can be accessed via the system tray icon.
|
||||
@@ -16,7 +20,16 @@ Any important events or actions taken by the script are logged both in a log fil
|
||||
### Configuration
|
||||
The script reads its configuration from a config.json file. This file contains the necessary information, such as your login credentials, the URL of the authentication portal, the SSID (network name) to which you want to connect, and the frequency of network checks in seconds.
|
||||
|
||||
## `Usage`
|
||||
## `Usage`
|
||||
|
||||
> [!IMPORTANT]
|
||||
> ### Python Requirements
|
||||
> If you are running it **directly with Python**, you need to install all the libraries that's used in the script and you need to install this specific library:
|
||||
> ```
|
||||
> python -m pip install requests "urllib3<2"
|
||||
> ```
|
||||
|
||||
|
||||
### Configuration
|
||||
Edit the config.json file with your specific information, including your login credentials, the portal URL, the SSID of the network you want to connect to, and the check interval in seconds. [Click to learn how to Configure the config.json](#how-to-configure-the-configjson)
|
||||
|
||||
@@ -27,9 +40,7 @@ When you run the script, a system tray icon will appear. Right-click on the icon
|
||||
You can view the log of the script's actions by clicking the "Show Log" option in the system tray menu.
|
||||
|
||||
## `How to Configure the config.json?`
|
||||
`"payload":` You need to find your own payload values. These are the values that your browser sends when you try to login with your credentials. For example username, phone number, password... To find that:
|
||||

|
||||
|
||||
`"payload":` You need to find your own payload values. These are the values that your browser sends when you try to login with your credentials. For example username, phone number, password, etc. To find that:
|
||||
- When you're in the login page, open your browser's Developer Tools, press F12 or Ctrl + Shift + I (or Cmd + Option + I on Mac) to open the Developer Tools. Alternatively, you can right-click anywhere on the page and select "Inspect" or "Inspect Element."
|
||||
- **Navigate to the Network Tab:** In the Developer Tools, click on the "Network" tab at the top.
|
||||
- **Trigger the POST Request:** Perform the action that sends the POST request. **(Try to login with incorrect password)**. The network tab will capture all network requests made by the page, including the POST request.
|
||||
@@ -37,23 +48,25 @@ You can view the log of the script's actions by clicking the "Show Log" option i
|
||||
- **Inspect the POST Data:** In the right-hand pane, you will see various tabs. Click on the "Payload" tab.
|
||||
In the "Payload" tab, you can find your form data or request payload that displays the data being sent with the POST request. This is where you can see your POST payload. You need to enter the same payload values to config.json.
|
||||
|
||||
`"url":` **DO NOT USE HTTPS, USE HTTP.** This is **NOT** the base URL of the login page. You can find this URL from the same page that you find your payload. It is called "Request URL", in the "Headers" tab. For example: "**http**://site.com/auth"
|
||||

|
||||
|
||||
`"url":` This is **NOT** the base URL of the login page. You can find this URL from the same page that you find your payload. It is called "Request URL", in the "Headers" tab.
|
||||

|
||||
|
||||
`"ssid":` This is your network's SSID. For example "MyHome_5G"
|
||||
|
||||
`"check_every_second":` The frequency of the script for checking your internet connection status. For example "100", it will try to access the internet every 100 seconds.
|
||||
|
||||
> Example useage:
|
||||
> ## Example useage:
|
||||
>
|
||||
> 
|
||||

|
||||
|
||||
## Dependencies
|
||||
The script uses various Python libraries, including requests for making HTTP requests, pystray for creating the system tray icon, and tkinter for the log window. Make sure you have all the required libraries.
|
||||
The script uses various Python libraries, including requests for making POST requests, pystray for creating the system tray icon, and tkinter for the log window. Make sure you have all the required libraries.
|
||||
|
||||
## Notes
|
||||
- The script relies on the assumption that the web portal uses basic HTTP authentication. If the portal uses a more complex login mechanism, additional adjustments may be necessary.
|
||||
- This script is primarily intended for Windows. Adaptations might be needed for other operating systems.
|
||||
> [!NOTE]
|
||||
> - The script relies on the assumption that the web portal uses basic authentication. If the portal uses a more complex login mechanism, additional adjustments may be necessary.
|
||||
> - This script is primarily intended for Windows. Adaptations might be needed for other operating systems.
|
||||
|
||||
## Disclaimer
|
||||
> Use this script responsibly and only on networks where you have the right to access and use the provided services. Unauthorized access to networks is illegal and unethical.
|
||||
|
||||
+6
-9
@@ -1,12 +1,9 @@
|
||||
{
|
||||
"payload": {
|
||||
"gsmNo": {
|
||||
"localGsmNo": "username",
|
||||
"gsmNoCountry": "country"
|
||||
},
|
||||
"password": "password"
|
||||
"username": "PLEASE WRITE YOUR OWN PAYLOAD VALUES HERE. THIS IS AN EXAMPLE",
|
||||
"password": "PLEASE WRITE YOUR OWN PAYLOAD VALUES HERE. THIS IS AN EXAMPLE"
|
||||
},
|
||||
"url": "http://website.com/api/portal/dynamic/authenticate",
|
||||
"ssid": "YOUR SSID",
|
||||
"check_every_second": 100
|
||||
}
|
||||
"url": "https://example.com/api/portal/dynamic/authenticate",
|
||||
"ssid": "WRITE YOUR SSID HERE",
|
||||
"check_every_second": 120
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Reference in New Issue
Block a user