You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
896 B
36 lines
896 B
5 years ago
|
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)
|