Skip to content

Instantly share code, notes, and snippets.

@Retord
Last active March 25, 2016 12:39
Show Gist options
  • Save Retord/8d420ccef9b30d5168f5 to your computer and use it in GitHub Desktop.
Save Retord/8d420ccef9b30d5168f5 to your computer and use it in GitHub Desktop.
Auto login into wishnet portal and connect to the internet when you get disconnected.
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import socket
import time
REMOTE_SERVER = "www.google.com"
login = 'http://192.168.183.201:9089/SEBS/Login.jsp'
def connect_it():
try:
browser = webdriver.Firefox()
browser.get(login) # the url given for login can also use www.google.com typing http (any protcol) is very important
url = browser.current_url
if url == login:
userElem = browser.find_element_by_name('Username') # id or name or link text etc can be used the intersted target can be used by inspect element
userElem.send_keys('user_name')
passwordElem = browser.find_element_by_name('Password')
passwordElem.send_keys('pass123')
okElement = browser.find_element_by_id('submit_btn')
okElement.click()
connectGo = browser.find_element_by_id('con')
connectGo.click()
return True
except:
pass
def internet_on():
try:
# see if we can resolve the host name -- tells us if there is
# a DNS listening
host = socket.gethostbyname(REMOTE_SERVER)
# connect to the host -- tells us if the host is actually
# reachable
s = socket.create_connection((host, 80), 2)
return True
except:
pass
return False
def start_check():
if internet_on() == False: #means net not connected
print 'Internet is not connected! connecting...'
if connect_it() == True:
print 'Internet is connected! sleeping for 10 mins!'
time.sleep(600)
start_check()
else:
print 'Internet is connected! sleeping for 10 mins!'
time.sleep(600)
start_check()
start_check();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment