-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_module.py
More file actions
41 lines (23 loc) · 731 Bytes
/
ssh_module.py
File metadata and controls
41 lines (23 loc) · 731 Bytes
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
import paramiko
import socket
def ssh_login(ip_addr, port, username, password):
# Build client and set policy
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Actual login code
try:
auth = client.connect(ip_addr, port, username=f'{username}', password=f'{password}', timeout=5)
# If the authentication fails
except paramiko.AuthenticationException:
return False
# If the server times out
except socket.error:
print("\nCould not connect to SSH server!\n")
exit()
# If there is some other random error
except Exception as e:
print("Unknown error occured with the SSH server!\n")
exit()
# If the authentication is successful
else:
return True