Compare commits

...
Author SHA1 Message Date
Deniz Şafak ffdfe53dfd Update HotspotAutoLogin.pyw
Added functionality for Ethernet networks.
2023-10-14 03:55:50 +03:00
Deniz Şafak 638233a901 Delete examples/Log.png 2023-10-13 14:55:50 +03:00
Deniz Şafak 15a646b833 Update README.md 2023-10-13 14:55:36 +03:00
Deniz Şafak d710811ec0 Add files via upload 2023-10-13 14:55:24 +03:00
Deniz Şafak e3f8c59baf Add files via upload 2023-10-13 14:54:00 +03:00
Deniz Şafak f0477fa63e Delete examples/Log.png 2023-10-13 14:53:41 +03:00
Deniz Şafak ab2f468230 Update HotspotAutoLogin.pyw
Fixed the issue of not being able to access the login URL even though network is connected.
2023-10-13 14:48:49 +03:00
Deniz Şafak 61dedb8592 Update README.md 2023-10-12 02:27:11 +03:00
Deniz Şafak 9c70bf1480 Update README.md 2023-10-12 01:32:15 +03:00
Deniz Şafak 40fda390bb Update README.md 2023-10-12 01:30:18 +03:00
Deniz Şafak f22d91d733 Update README.md 2023-10-12 01:29:57 +03:00
Deniz Şafak 89fd7ee615 Update README.md 2023-10-12 01:28:41 +03:00
Deniz Şafak f17a881e86 Update README.md 2023-10-12 01:27:20 +03:00
Deniz Şafak 3ff98344a1 Update README.md 2023-10-12 01:26:07 +03:00
4 changed files with 66 additions and 46 deletions
+54 -35
View File
@@ -1,14 +1,14 @@
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
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += 'HIGH:!DH:!aNULL'
@@ -40,23 +40,40 @@ def is_internet_available():
# If an exception is raised, there's no internet connectivity
return False
# Function to get the currently connected WiFi SSID using system commands (for Windows)
def get_connected_wifi_ssid():
# Function to get the currently connected SSID using system commands (for Windows)
def get_connected_network():
try:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
output = subprocess.check_output(["netsh", "wlan", "show", "interfaces"], startupinfo=startupinfo).decode("utf-8")
lines = output.split("\n")
for line in lines:
# Get Wi-Fi SSID
wifi_output = subprocess.check_output(["netsh", "wlan", "show", "interfaces"], startupinfo=startupinfo).decode("utf-8")
wifi_lines = wifi_output.split("\n")
wifi_ssid = None
for line in wifi_lines:
if "SSID" in line:
ssid = line.strip().split(": ")[1]
return ssid
return None
wifi_ssid = line.strip().split(": ")[1]
break
if wifi_ssid is not None:
return wifi_ssid
elif wifi_ssid is None:
# Check if connected to Ethernet
ethernet_output = subprocess.check_output(["netsh", "interface", "show", "interface"], startupinfo=startupinfo).decode("utf-8")
ethernet_lines = ethernet_output.split("\n")
for line in ethernet_lines:
if "Connected" in line:
if "Ethernet" in line:
return "Ethernet Network"
else:
return None
except subprocess.CalledProcessError:
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)
@@ -145,7 +162,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
@@ -153,49 +170,51 @@ def check_network_status():
errorcount = 0
sleepcount = config["check_every_second"]
while running and errorcount < 10:
connected_ssid = get_connected_wifi_ssid()
if connected_ssid and connected_ssid.lower() == expected_ssid:
connected_ssid = get_connected_network()
if connected_ssid.lower() == expected_ssid or connected_ssid == "Ethernet Network":
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:
sleepcount = 10 # Sleep ... seconds before trying again
message = "Not connected to "+config["ssid"]+" Checking again in "+str(sleepcount)+" seconds..."
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
+12 -11
View File
@@ -1,16 +1,17 @@
# HotspotAutoLogin Wi-Fi/Hotspot Autologin Script (Automate WEB Logins)
HotspotAutoLogin is a script that 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.
> # [Download the Latest Executable (.exe) Release](../../releases)
![Example Log.](/examples/Logs.png)
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.
![Example Log.](/examples/Log.png)
## `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
### 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
@@ -23,7 +24,7 @@ The script reads its configuration from a config.json file. This file contains t
> [!IMPORTANT]
> ### Python Requirements
> If you are running it **directly with Python**, you need to install this specific library:
> 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"
> ```
@@ -39,7 +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.
@@ -58,14 +59,14 @@ In the "Payload" tab, you can find your form data or request payload that displa
> ## Example useage:
>
> ![Example config.ini.](/examples/config.png)
![Example Request.](/examples/config.png)
## Dependencies
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 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.
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB