-
Notifications
You must be signed in to change notification settings - Fork 0
/
fortigate_ssh_getinfo_02.py
49 lines (40 loc) · 1.36 KB
/
fortigate_ssh_getinfo_02.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
import paramiko
class SSH:
def __init__(self,IP,USER,PASSWORD):
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(hostname=IP,username=USER,password=PASSWORD)
def comando_ssh(self,cmd):
stdin,stdout,stderr = self.ssh.exec_command(cmd)
if stderr.channel.recv_exit_status() != 0:
out = stderr.readlines()
else:
out = stdout.readlines()
return out
def get_info(IP,USER,PASSWORD,COMANDO):
conexao = SSH(IP,USER,PASSWORD)
out = conexao.comando_ssh(COMANDO)
out = list(map(lambda x:x.strip(),out)) #remove \n da lista
return out
def get_firewall(IP,USER,PASSWORD,COMANDO):
conexao = SSH(IP,USER,PASSWORD)
out = conexao.comando_ssh(COMANDO)
out = list(map(lambda x:x.strip(),out)) #remove \n da lista
return out
def main():
ip = '10.1.1.0'
username = 'fortionly'
password = 'senha'
conexao = SSH(ip,username,password)
out = get_info(ip,username,password,'get system status')
cont=0
while cont < 28:
print(out[cont])
cont=cont 1
out = get_firewall(ip,username,password,'config vdom \n edit BGP-AS \n get system performance firewall statistics')
cont=0
while cont < 21:
print(out[cont])
cont=cont 1
if __name__ == '__main__':
main()