Skip to content

Instantly share code, notes, and snippets.

@aanarchyy
Created March 17, 2018 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aanarchyy/847f3c703be08856c0b3ab62db340b22 to your computer and use it in GitHub Desktop.
Save aanarchyy/847f3c703be08856c0b3ab62db340b22 to your computer and use it in GitHub Desktop.
Log into xfinitywifi
#!/bin/bash
### DEFINE ###
iface=wlan3 #Set this to the interface you are using
loop=2
iam=`whoami`
lapse=0
online=0
force=0
ecount=0
onrouter=0
### END DEFINE ###
#Checks to see if run by the root user, need to be root
if [ "$iam" != "root" ]
then
echo "You must be root!"
exit 1
fi
trap ctrl_c EXIT
### FUNCTIONS ###
ctrl_c()
{
#echo -e "\nQuiting!!\n"
exit 0
}
#Example: randmac [interface]
#Pull the interface down, randomize the mac, and bring it back up
randmac()
{
ifconfig $iface down
ipaddr=""
macchanger -a $iface
rfkill unblock all
ifconfig $iface up
}
#Example: checkcon [IP] [variable]
#pings the IP, and setes the variable to the errorlevel
checkcon()
{
local __resultvar=$2
ping $1 -c 1 -q -W 3 &> /dev/null
eval $__resultvar=$?
}
connect()
{
sleep 1
notify-send -u normal -t 10000 "Reconnecting"
set -f
ifconfig $iface down
ipaddr=""
errorlevel=1
ecount=0
while [ "$ipaddr" != "172.20.20.20" ] ; do
/etc/init.d/dnsmasq restart &> /dev/null
randmac $iface &> /dev/null
iwconfig $iface essid xfinitywifi &> /dev/null
echo -ne "IP: $ipaddr \r"
dhclient -v -i $iface &> /dev/null &
sleep 10 #Give it ten seconds to get an IP address
#If it can't get one by then, kill the client
#Likely a bad connection, or the router kicked us
kill -9 `pidof dhclient` > /dev/null 2>&1
#Peeling the assigned IP address out
#ipaddr=`/sbin/ifconfig $iface | grep inet\ addr | sed -e 's/inet addr://g' -e 's/^[ \t]*//' | awk -F' ' '{print $1}'`
ipaddr=`hostname -I | tr -d '[:space:]'`
echo -ne "IP: $ipaddr \r"
sleep 2
#xfinitywifi always assigns the same IP address, check to see if we have it
while [ "$errorlevel" != "0" -a "$ipaddr" = "172.20.20.20" ]
do
python xfinlogin.py
errorlevel=$?
#echo "ErrorLevel: $errorlevel"
if [ "$errorlevel" != 0 ] ; then #If the script fails or crashes...
kill -9 `pidof firefox-esr` &> /dev/null
kill -9 `pidof firefox-bin` &> /dev/null
((ecount++))
echo "Error Count: $ecount"
if [ "$ecount" -gt "2" ] ; then #Reset everything and reconnect
ipaddr=""
ipaddr[1]=""
ecount=0
fi
fi
done
done
online=1
notify-send -u normal -t 10000 "Internet Active!"
}
### END FUNCTIONS ###
while getopts ocr opt
do
case $opt in
o) loop=1;;
c)
connect $iface
;;
r)
randmac $iface
;;
f)
;;
esac
done
while [ $loop == 2 ] ; do
if [ $online -gt 0 ] ; then
echo -en "Connecting\r"
lapse=0
connect
fi
checkcon 8.8.8.8 online
#checkcon 172.20.20.1 onrouter
#while [ $lapse -lt 54 ] && [ $online -eq 0 -a $onrouter -eq 0 ] ; do
while [ $lapse -lt 54 -a $online -eq 0 ] ; do
echo -en "$lapse \r"
notify-send -u low -t 10000 "$lapse"
sleep 300
let "lapse = $lapse + 5"
checkcon 8.8.8.8 online
#checkcon 172.20.20.1 onrouter
done
online=1
done
#!/usr/bin/python
import time , string, random, sys, subprocess
import socket, signal
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
### DEFINE VARIABLES ###
foxbin = "/usr/lib/firefox-esr/firefox-esr"
#foxbin = "/home/kilroy/Downloads/firefox/firefox-bin"
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False
binary = FirefoxBinary(foxbin)
RETRIES = 3
delay = 15
lapse = 0
online = False
ecount = 0
url = "http://1.1.1.1"
#url = "http://wifi.comcast.com"
#url = "http://firefox.detectportal.com"
### END DEFINE VARIABLES ###
#Launch Firefox
driver = webdriver.Firefox(firefox_binary=binary, capabilities=capabilities)
### FUNCTIONS ###
def signal_handler(signal, frame):
print('Ctrl+C!')
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
def randascii(size, char):
chars = ""
if "u" in char:
chars = chars + string.ascii_uppercase
if "l" in char:
chars = chars + string.ascii_lowercase
if "n" in char:
chars = chars + string.digits
return ''.join(random.choice(chars) for _ in range(size))
def find_element_by_id(elem):
tries = 0
#element = None
while tries < RETRIES:
try:
element = driver.find_element_by_id(elem)
except TimeoutException:
tries = tries + 1
print('Timeout Retry:%s' % (tries))
driver.refresh()
continue
except NoSuchElementException:
tries = tries + 1
print('NoSuchElementException FIND Retry:%s for %s' % (tries, elem))
driver.refresh()
else:
return element
raise NoSuchElementException("Element with id=%s was not found." % id)
print("Element:id=%s not found." % id)
driver.close()
#sys.exit(1)
def main():
try:
driver.get(url)
except NoSuchElementException:
print("NoSuchElementException MAIN")
driver.close()
return False
sys.exit(1)
except TimeoutException as ex:
isrunning = 0
print("Exception has been thrown. " + str(ex))
return False
driver.close()
sys.exit(1)
linkElem = find_element_by_id('not-xfinity-customer')
type(linkElem)
linkElem.click()
element = WebDriverWait(driver, delay).until(
lambda x: x.find_element_by_link_text('Get a WiFi On Demand Pass'))
linkElem = driver.find_element_by_link_text('Get a WiFi On Demand Pass')
time.sleep(1)
linkElem.click()
linkElem.click()
#linkElem = find_element_by_id('amdocs_signup')
#type(linkElem)
#linkElem.click()
element = WebDriverWait(driver, delay).until(
lambda x: x.find_element_by_id("offersFreeList"))
linkElem = find_element_by_id('offersFreeList')
linkElem.click()
linkElem = find_element_by_id('continueButton')
linkElem.click()
print("Step 1 ", end="\r")
element = WebDriverWait(driver, delay).until(
lambda x: x.find_element_by_id("registerFirstName"))
linkElem = find_element_by_id('registerFirstName')
rand = randascii(12, "l")
linkElem.send_keys(rand)
linkElem = find_element_by_id('registerLastName')
rand = randascii(12, "l")
linkElem.send_keys(rand)
linkElem = driver.find_element_by_id('registerEmail')
rand = randascii(12, "l")
email = rand + "@gmail.com"
linkElem.send_keys(email)
linkElem = find_element_by_id('registerZipCode')
rand = randascii(6, "n")
linkElem.send_keys(rand)
time.sleep(3)
linkElem = find_element_by_id('registerContinueButton')
linkElem.click()
print("Step 2", end="\r")
element = WebDriverWait(driver, delay).until(
lambda x: x.find_element_by_id("usePersonalEmail"))
linkElem = find_element_by_id('usePersonalEmail')
linkElem.click()
#time.sleep(1)
rand = randascii(12, "lun")
passw = rand + "aB1!"
linkElem = find_element_by_id('password')
linkElem.send_keys(passw)
time.sleep(1)
passwd_confirm = linkElem.get_attribute("value")
linkElem = find_element_by_id('passwordRetype')
linkElem.clear()
#time.sleep(1)
linkElem.send_keys(passw)
time.sleep(1)
linkElem = find_element_by_id('dk0-combobox')
linkElem.click()
#linkElem.send_keys(' ')
linkElem.send_keys('what')
linkElem.send_keys(' ')
#time.sleep(1)
linkElem = find_element_by_id('secretAnswer')
linkElem.send_keys('your mom')
time.sleep(1)
linkElem = find_element_by_id('submitButton')
linkElem.click()
print("Step 3", end="\r")
element = WebDriverWait(driver, delay).until(
lambda x: x.find_element_by_id("orderConfirmationActivatePass"))
linkElem = find_element_by_id('orderConfirmationActivatePass')
time.sleep(1)
linkElem.click()
time.sleep(10)
driver.close()
timenow = subprocess.check_output(['date', '+%R']).decode('utf-8')
_time = timenow.split(":")
hour = int(_time[0]) + 1
if (hour>23):
hour="00"
timeup= str(hour) + ":" + _time[1]
print("Pass expires at %s" % timeup, end="\r")
return True
sys.exit(0)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment