This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangewifipass.py
52 lines (43 loc) · 1.71 KB
/
changewifipass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python2.7
import pxssh
import getpass
import random
import smtplib
import time
DEFAULT_WORD_FILE = 'words-simpsons.txt'
def __get_words():
words = []
try:
with open(DEFAULT_WORD_FILE, 'rb') as fd:
words = [line.strip() for line in fd.readlines()]
except (IOError, OSError):
parser.error('%s file is not found. Abort!' % DEFAULT_WORD_FILE)
return words
def gen_passphrase(words, num_words=5):
passphrase = []
for i in xrange(num_words):
index = random.SystemRandom().randrange(len(words))
passphrase.append(words[index])
return "-".join(passphrase)
def sendemail(from_addr, to_addr_list,
subject, message
):
header = 'From: %s\n' % from_addr
header += 'To: %s\n' % ','.join(to_addr_list)
header += 'Subject: %s\n\n' % subject
message = header + message
server = smtplib.SMTP("localhost")
problems = server.sendmail(from_addr, to_addr_list, message)
server.quit()
words = __get_words()
password = gen_passphrase(words,4)
try:
s = pxssh.pxssh()
s.login ("hostname","root","pass")
s.sendline ('uci set wireless.@wifi-iface[0].key="%s";uci commit wireless;wifi;wifi' % password) # run a command
s.prompt() # match the prompt
s.logout()
sendemail("[email protected]",["[email protected]","[email protected]"],"Neues WLAN-Passwort","Ab sofort ist auf dem Wlan-Access-Point tempelderlust folgedenes Passwort gesetzt: %s\n\nDer Passwortwechsel wurde praesentiert von den Netzwerk-Alumni" % password)
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)