-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_ssh_pi.py
60 lines (51 loc) · 1.57 KB
/
python_ssh_pi.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
52
53
54
55
56
57
58
59
60
import pxssh
import getpass
#class ip_Exception(Exception):
#'''If wrong formatted ip was entered'''
#def __init__(self,
class address:
ip_prefix = "192.168.1"
def __init__(self,user,hostip,pswd):
self.suffix = 0
self.user = user
ip_prefix = hostip
self.host_ip = "{}.{}".format(ip_prefix,self.suffix)
self.password = pswd
#def check(self):
def next_ip(self):
self.suffix+=1
self.host_ip = "{}.{}".format(ip_prefix,self.suffix)
def ip(self):
return self.host_ip
def us(self):
return self.user
def pwd(self):
return self.pwd
def main():
s = pxssh.pxssh()
hostname = raw_input('host-ip (without last number): ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
cl = address(username,hostname,password)
for i in range(256):
print i,":"
try:
s.login (cl.us,cl.ip,cl.pwd)
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
cl.next_ip
pass
print "Login Success"
s.sendline ('uptime') # run a command
s.prompt() # match the prompt
print s.before # print everything before the prompt.
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.logout()
if __name__ == "__main__":
main()