Skip to content

Commit b4eed8f

Browse files
Create LinPyAuto.py
Sample Script For Off-Box Network Automation On Linux Distributions
1 parent 9ea3c2e commit b4eed8f

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

Parmiko-Linux-Example/LinPyAuto.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import paramiko
2+
3+
def Server1():
4+
l_password = "Password"
5+
l_host = "IP"
6+
l_user = "UserName"
7+
ssh = paramiko.SSHClient()
8+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
9+
ssh.connect(l_host, username=l_user, password=l_password)
10+
transport = ssh.get_transport()
11+
session = transport.open_session()
12+
session.set_combine_stderr(True)
13+
session.get_pty()
14+
session.exec_command("ls")
15+
stdin = session.makefile('wb', -1)
16+
stdout = session.makefile('rb', -1)
17+
stdin.write(l_password +'\n')
18+
stdin.flush()
19+
for line in stdout.read().splitlines():
20+
print ('host: %s: %s' % (l_host, line))
21+
22+
#For Other Servers
23+
def Server2():
24+
l_password = "Password"
25+
l_host = "IP"
26+
l_user = "UserName"
27+
ssh = paramiko.SSHClient()
28+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
29+
ssh.connect(l_host, username=l_user, password=l_password)
30+
transport = ssh.get_transport()
31+
session = transport.open_session()
32+
session.set_combine_stderr(True)
33+
session.get_pty()
34+
session.exec_command("sudo brctl show")
35+
stdin = session.makefile('wb', -1)
36+
stdout = session.makefile('rb', -1)
37+
stdin.write(l_password +'\n')
38+
stdin.flush()
39+
for line in stdout.read().splitlines():
40+
print ('host: %s: %s' % (l_host, line))
41+
42+
#For Other Servers
43+
44+
def Server3():
45+
l_password = "Password"
46+
l_host = "IP"
47+
l_user = "UserName"
48+
ssh = paramiko.SSHClient()
49+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
50+
ssh.connect(l_host, username=l_user, password=l_password)
51+
transport = ssh.get_transport()
52+
session = transport.open_session()
53+
session.set_combine_stderr(True)
54+
session.get_pty()
55+
session.exec_command("Command")
56+
stdin = session.makefile('wb', -1)
57+
stdout = session.makefile('rb', -1)
58+
stdin.write(l_password +'\n')
59+
stdin.flush()
60+
for line in stdout.read().splitlines():
61+
print ('host: %s: %s' % (l_host, line))
62+
63+
64+
#For Other Servers
65+
66+
def Server4():
67+
l_password = "Password"
68+
l_host = "IP"
69+
l_user = "UserName"
70+
ssh = paramiko.SSHClient()
71+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
72+
ssh.connect(l_host, username=l_user, password=l_password)
73+
transport = ssh.get_transport()
74+
session = transport.open_session()
75+
session.set_combine_stderr(True)
76+
session.get_pty()
77+
session.exec_command("Command")
78+
stdin = session.makefile('wb', -1)
79+
stdout = session.makefile('rb', -1)
80+
stdin.write(l_password +'\n')
81+
stdin.flush()
82+
for line in stdout.read().splitlines():
83+
print ('host: %s: %s' % (l_host, line))
84+
85+
def Server5():
86+
l_password = "Password"
87+
l_host = "IP"
88+
l_user = "UserName"
89+
ssh = paramiko.SSHClient()
90+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
91+
ssh.connect(l_host, username=l_user, password=l_password)
92+
transport = ssh.get_transport()
93+
session = transport.open_session()
94+
session.set_combine_stderr(True)
95+
session.get_pty()
96+
session.exec_command("Command")
97+
stdin = session.makefile('wb', -1)
98+
stdout = session.makefile('rb', -1)
99+
stdin.write(l_password +'\n')
100+
stdin.flush()
101+
for line in stdout.read().splitlines():
102+
print ('host: %s: %s' % (l_host, line))
103+
104+
Server1()
105+
#Server2()
106+
#Server3()
107+
#Server4()
108+
#Server5()

0 commit comments

Comments
 (0)