Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Last active December 12, 2015 01:48
Show Gist options
  • Save thefinn93/4693315 to your computer and use it in GitHub Desktop.
Save thefinn93/4693315 to your computer and use it in GitHub Desktop.
Frontier FiOS related stuff.
#!/usr/bin/env python
import telnetlib
import getpass
import ConfigParser
import os
import sys
## Configuration ##
# The default values are probably good
# How much shit gets spewed onto the screen about what's going on.
# Anything above 1 gives messages on every attempt (at minimum).
# That's a lot of god damn messages.
loglevel = 0
# This is just the IP or hostname of the modem
#(so I know where to telnet to)
host = "192.168.1.1"
# This is the list of characters to use. Feel free to extend it.
characterset = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
# This is what the prompt looks like. I look for it to know when
# I can enter the next command.
prompt = "Wireless Broadband Router> " # Notice the tailing space!
# The config file can store a username and password so I don't have to ask
# at every run. Note that, while this is probably insecure, we're talking
# about a frontier modem here, so it's probably insecure anyway.
config = os.getenv("HOME") + "/.config/frontier.ini"
# This isn't really config, but it's the labels for the log levels above.
levels = ["FOUND", "INFO", "DEBUG", "EXCESSIVE DEBUG"]
# OK now the config is over.
def dbg(level, msg):
if level <= loglevel:
print levels[level] + ": " + msg
dbg(1, "Log level is set to " + levels[loglevel])
dbg(1, "Assuming IP is " + host + ". Edit this script to change that")
print "First I'll need a username and password for the modem"
# Todo: Allow these to be read from a config file
user = raw_input("Username: ")
passwd = getpass.getpass("Password: ")
save = raw_input("Would you like to save those credentials in " + config + "? [y/N] ");
dbg(2, "Connecting to " + host)
tn = telnetlib.Telnet(host)
dbg(3, "Connected")
tn.read_until("Username: ")
dbg(3, "Username requested")
tn.write(user + "\n")
dbg(3, "Uername sent")
tn.read_until("Password: ")
dbg(3, "Password requested")
tn.write(passwd + "\n")
dbg(3, "Password sent, waiting for " + prompt)
dbg(2, tn.read_until(prompt))
dbg(1,"Logged in. Initing teh lulz")
path = []
if len(sys.argv) == 2:
for char in sys.argv[1]:
path.append(characterset.index(char))
dbg(1, "Starting at " + sys.argv[1] + " per your request")
else:
path = [0]
def increment(path):
dbg(3, "Incrementing " + str(path))
done = False
position = len(path)-1
while not done:
if path[position] == len(characterset)-1: # If we're at the end of the characterset
dbg(2, "Incrimenting character " + str(position))
if position == 0: # If we're at the beginning of the string
path[position] = 0 # Set the first character in the string to the first character in the set
path.append(0) # and add another one to the end
done = True # Then exit the loop
dbg(1, "Increasing to " + str(len(path)) + " characters")
else:
path[position] = 0
position = position-1
else:
path[position] = path[position] + 1
done = True
return path
def trypath(textpath):
dbg(2, "Trying " + textpath)
tn.write("conf print " + textpath + "\n")
returned = tn.read_until(prompt)
#print "> " + returned
length = len(returned.split("\n"))
if length != 4:
return True
else:
return False
try:
while True: # Infinite loops are fun!
textpath = "/"
for char in path:
textpath = textpath + characterset[char]
if trypath(textpath): # Sometimes we get a false positive
if trypath(textpath): # because it occationally spews debug info to the console
dbg(0, textpath)
path = increment(path)
except KeyboardInterrupt:
textpath = "/"
for char in path:
textpath = textpath + characterset[char]
dbg(1, "Stopped. Last value tried was " + textpath + ". To resume, run " + sys.argv[0] + " " + textpath[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment