Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hotspot automatic reconnect script
#1
Hey guys.Im often connected to a nearby hotspot, but there is always a trouble cause I have to go to a login page and simply press "connect" like every 20 mins and it can be disturbing sometimes, so I was thinking about writing down some python code to continously send the same GET every second and just let it run in the bg when Im conneted to this network, but I've did never any serious networking stuff with python, can somebody point my at how this script should look like?

Regards.
Reply
#2
Im trying to remake some scrapper to force it to reconnect me but I cant make it work.
import requests
from bs4 import BeautifulSoup

def reconnect(r):
    r = requests.get("http://myhotspot.de/login?dst=http%3A%2F%2Fgoogle.com%2F&username=T-00%3AE4%3A5C%3A09%3A42%3A9A")
    soup = BeautifulSoup(r.content, "html.parser")
    print(r),(r.content)
    print(soup.prettify())
    print (type(soup))
    return

while 1 < 2: 
    reconnect
Reply
#3
(May-01-2018, 09:37 PM)blackknite Wrote: Im trying to remake some scrapper to force it to reconnect me but I cant make it work.
I guess log in is okay and you get log out after some time.
schedule is what i use if not doing it from OS.
So this code will run reconnect function every minute,
no r parameter in your function as it get created inside function.
import requests
from bs4 import BeautifulSoup
# pip install schedule
import schedule

def reconnect():
    r = requests.get("http://myhotspot.de/login?dst=http%3A%2F%2Fgoogle.com%2F&username=T-00%3AE4%3A5C%3A09%3A42%3A9A")
    soup = BeautifulSoup(r.content, "html.parser")
    print(r),(r.content)
    print(soup.prettify())
    print (type(soup))
    return

schedule.every(1).minutes.do(reconnect)
while True:
    schedule.run_pending()
    time.sleep(1)
Reply
#4
I did so many versions of this script, but all got some issues.

import requests
#import schedule
import time
from bs4 import BeautifulSoup

def countdown():
    for i in reversed(range(0, 1)):
        time.sleep(1)
        print("%s\r" %i)


def reconnect():
    r = requests.get("http://hotspot.de/login?dst=http%3A%2F%2Fgoogle.com%2F&username=here")
    soup = BeautifulSoup(r.content, "html.parser")
    
    print(r),(r.content)
    print(soup.prettify())
    print (type(soup))
    
    countdown()
    reconnect()
    return

reconnect()
This one works nice but stops after some time with error about reaching maximum recursion limit, and im definitely too noob in python to know how to fix it.

And the version with just one scheduled request got some weird time issue, when I use the script to connect and schedule it to send next get in exactly 30 minutes it doesnt follow the server time, after running 2 hours the discord is minutes long.I think better way for doing precised request would be to scrap some site and basing on length of this GET, send request only if it gets error, so it would be a most notebook friendly method.

The very first version with tons of GET every second, was eating up to 30% and always has some serverside ban risk so its not good at all.

I will try to get to work somehow this version posted above, thus I dont know how yet, there are some articles warning about forcing higher recursion depth on a python interpreter Huh

And just a fast thought, maybe will TRY do some exception to make run the script again after falling down, but idk if its possible here.
Reply
#5
I dont focking get it, I have reconnect() after connection error but it keeps stopping on it.I just want this script to run even if there is no internet connection at all, why this focking shit have to be so complicated.

import requests
#import schedule
import time
from bs4 import BeautifulSoup
import pymsgbox
import atexit
___author____: "blackknite"



def countdown():
    for i in reversed(range(0, 1)):
        time.sleep(1)
        print("%s\r" %i)


def reconnect():
    r = requests.get("loginlink")
    soup = BeautifulSoup(r.content, "html.parser")
    
    print(r),(r.content)
    print(soup.prettify())
    print (type(soup))
    

    countdown()
    reconnect() 
    return

try:
    reconnect()
except (RuntimeError, TypeError, NameError, ConnectionError, RecursionError):
    reconnect()
except RuntimeError as re:
    if re.args[0] != 'maximum recursion depth exceeded in comparison':
        raise
        pymsgbox.alert('Script failed!', 'Falling down') 
finally:
     reconnect()
     atexit.register(reconnect())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Automatic login hidden form Andra111 0 1,627 Mar-26-2020, 08:06 AM
Last Post: Andra111

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020