Created
February 1, 2018 21:49
-
-
Save skbly7/5939dc0f252e91af27d277ba3e9ed376 to your computer and use it in GitHub Desktop.
Scripted guest account creation in Cisco Wireless Controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
controller = '10.0.0.0' # Cisco controller IP | |
username = 'admin' | |
password = 'password_here' | |
user_file = 'users.csv' | |
description = 'ISEC User' | |
# Check WLAN ID from Controller! | |
# http://10.0.0.0/screens/apf/wlan_list.html | |
wlanID = '4' # IIIT-Guest | |
################################################### | |
############# DO NOT CHANGE THINGS BELOW ########## | |
################################################### | |
import mechanize | |
import cookielib | |
from BeautifulSoup import BeautifulSoup | |
import html2text | |
import uuid | |
# Browser | |
br = mechanize.Browser() | |
# Cookie Jar | |
cj = cookielib.LWPCookieJar() | |
br.set_cookiejar(cj) | |
# Browser options | |
br.set_handle_equiv(True) | |
br.set_handle_gzip(True) | |
br.set_handle_redirect(True) | |
br.set_handle_referer(True) | |
br.set_handle_robots(False) | |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) | |
br.addheaders = [('User-agent', 'Chrome')] | |
# The site we will navigate into, handling it's session | |
br.add_password('http://'+controller+'/', username, password) | |
def create_user(username, password): | |
br.open('http://'+controller+'/screens/aaa/netuser_create.html') | |
br.select_form(nr=0) | |
br.form.set_all_readonly(False) | |
br.form['username'] = username | |
br.form['userpwd'] = password | |
br.form['pwdconfirm'] = password | |
br.form['UserWlanID'] = [wlanID,] | |
br.form['description'] = description | |
br.form['buttonClicked'] = wlanID | |
br.submit() | |
with open(user_file, "r") as usernames: | |
for username in usernames: | |
username = username.strip() | |
password = uuid.uuid4().hex[:8].upper() | |
print username + ',' + password | |
create_user(username, password) |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
email1@domain1.com | |
email2@domain2.com | |
email3@domain3.com | |
email4@domain4.com | |
email5@domain5.com | |
email6@domain6.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment