-
Notifications
You must be signed in to change notification settings - Fork 4
/
sshhp
executable file
·55 lines (46 loc) · 1.52 KB
/
sshhp
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
#!/usr/bin/env python3
import sys
from getpass import getpass
from lib.cli import Cli
from lib import hpshell
def checkArgument():
if len(sys.argv) != 2:
print("http - Connect a switch through HTTP protocal")
print("Usage: http [user@]host")
print("(If not specified, username is admin.)")
sys.exit(0)
def parseArgument():
if '@' in sys.argv[1]:
return sys.argv[1].split('@')
else:
return "admin", sys.argv[1]
def execPrompt(cli):
hpshell.run(cli)
if __name__ == "__main__":
checkArgument()
user, host = parseArgument()
# Always try https first!
if Cli.testConnection('https', host):
cli = Cli('https', host)
print("Connect through HTTPS successfully")
print("Note: This program will NOT verify the SSL certificate.")
else:
print("HTTPS failed. Try HTTP...")
if Cli.testConnection('http', host):
cli = Cli('http', host)
print("*****************************************")
print("*Warning: Connect through HTTP protocal.*")
print("*****************************************")
else:
print("Error: Cannot connect to remote host through HTTP and HTTPS.")
sys.exit(0)
wrong_times = 0
while wrong_times < 3:
password = getpass('Password: ')
if cli.login(user, password):
break
wrong_times += 1
if wrong_times >= 3:
print("3 incorrect password attempts")
sys.exit(0)
execPrompt(cli)