Created
May 13, 2024 11:09
-
-
Save xjunko/1fc868772327a05c800d708e31ac888d to your computer and use it in GitHub Desktop.
dumb wifi trial reset script for ungku omar polytechnic, resets every 30 minutes automatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" puo_dumb_wifi.py - simple wifi trial reset script """ | |
__author__ = "xJunko" | |
__world__ = "antipathy" | |
import subprocess | |
import time | |
import urllib.request | |
# Too lazy to do argumentparser, hardcoded it is then. | |
WLAN_INTERFACE: str = "wlan0" | |
def get_mac_address(interface: str) -> str: | |
mac_address = subprocess.check_output(["ip", "link", "show", interface]) | |
mac_address = mac_address.decode("utf-8").split("\n")[1].split(" ")[5] | |
return mac_address | |
def notification(title: str, message: str) -> None: | |
subprocess.call(["notify-send", title, message]) | |
def fuck_shit_up() -> int: | |
current_mac_address: str = get_mac_address(WLAN_INTERFACE) | |
print("> Current MAC Address: ", get_mac_address(WLAN_INTERFACE)) | |
print("> Changing MAC Address...") | |
notification("PUO WIFI", "Refreshing!") | |
subprocess.call(["sudo", "networkctl", "down", WLAN_INTERFACE]) | |
subprocess.call(["sudo", "macchanger", "-r", WLAN_INTERFACE]) | |
subprocess.call(["sudo", "networkctl", "up", WLAN_INTERFACE]) | |
new_mac_address: str = get_mac_address(WLAN_INTERFACE) | |
if new_mac_address == current_mac_address: | |
print("> Failed to change MAC Address.") | |
return 1 | |
print("> New MAC Address: ", new_mac_address) | |
# Impose delay for a bit, because technology. | |
time.sleep(2) | |
# PUO Trial API | |
api_attempt: int = 0 | |
while api_attempt < 3: | |
api_attempt += 1 | |
try: | |
url = ( | |
f"http://wifi.aeronet.com.my/login?username=T-{new_mac_address.upper()}" | |
) | |
urllib.request.urlopen(url) | |
break | |
except: | |
print("> API broken, retrying") | |
notification("PUO WIFI", "API broken, retrying\\!") | |
time.sleep(2) | |
continue | |
# Get request to google to check if internet is working. | |
try: | |
urllib.request.urlopen("http://google.com", timeout=1) | |
print("> Internet is working.") | |
notification("PUO WIFI", "Connection Refreshed\\!") | |
except urllib.error.URLError: | |
print("> Internet is not working.") | |
notification("PUO WIFI", "Failed to refresh connection, shits fucked.\\!") | |
return 0 | |
def main() -> int: | |
try: | |
while True: | |
notification("PUO WIFI", "Internet reset incoming\\!") | |
time.sleep(0.5) | |
for i in range(3, 0, -1): | |
notification("PUO WIFI", f"{i}") | |
time.sleep(1) | |
fuck_shit_up() | |
print("> Internet will be refreshed again in 30 minutes.") | |
time.sleep(30 * 60) | |
except Exception: | |
print("> Loop terminated, bye :D.") | |
return 0 | |
if __name__ == "__main__": | |
raise SystemExit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment