commit a30cc63da33777313c5f6e7a8d64fead15fdb1ed Author: Tanner Collin Date: Sat Apr 20 21:17:37 2019 +0700 Initial commit diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9ce4767 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +certifi==2019.3.9 +chardet==3.0.4 +idna==2.8 +pkg-resources==0.0.0 +requests==2.21.0 +urllib3==1.24.2 diff --git a/thaiwifi.py b/thaiwifi.py new file mode 100644 index 0000000..7128974 --- /dev/null +++ b/thaiwifi.py @@ -0,0 +1,35 @@ +import logging +logging.basicConfig( + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=logging.INFO) + +import os +import requests +import time + +COUNT = 5 +TIMEOUT = 1 +INTERVAL = 0.2 +HOST = '192.168.50.1' +PING_COMMAND = 'ping -c {} -W {} -i {} {} > /dev/null 2>&1' + +LOGIN_URL = 'http://login.tulip.biz/portal/user-authen.php' +LOGIN = dict(txtLogin='tb215', txtPasswd='363499') +LOGIN_TIMEOUT = 10 + +while True: + try: + connected = not os.system(PING_COMMAND.format(COUNT, TIMEOUT, INTERVAL, HOST)) + + if not connected: + requests.post(LOGIN_URL, data=LOGIN, timeout=LOGIN_TIMEOUT) + logging.info('Attempted to login.') + time.sleep(10) + + time.sleep(0.5) + except KeyboardInterrupt: + logging.info('Exiting...') + break + except BaseException as e: + logging.error(str(e)) + time.sleep(10) diff --git a/thaiwifi.sh b/thaiwifi.sh new file mode 100644 index 0000000..77f067f --- /dev/null +++ b/thaiwifi.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +################## +# Old cron script +################## + +if curl http://t0.vc/f/wifi-test.txt | grep -q 'Please wait while you are redirected'; then + curl 'http://login.tulip.biz/portal/user-authen.php' --data 'txtLogin=tb215&txtPasswd=363499&btnLogin=Login&reqUrl=http%3A%2F%2Fgoo.gl%2Fe4wv&reqCheck=false' +fi