|
|
|
@@ -1,6 +1,9 @@
|
|
|
|
#!/usr/bin/env python3.10
|
|
|
|
#!/usr/bin/env python3.10
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
from csv import DictReader
|
|
|
|
from csv import DictReader
|
|
|
|
|
|
|
|
import os, socket
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_csv(csv_file = str):
|
|
|
|
def read_csv(csv_file = str):
|
|
|
|
with open(csv_file, newline='') as csv:
|
|
|
|
with open(csv_file, newline='') as csv:
|
|
|
|
@@ -8,32 +11,44 @@ def read_csv(csv_file = str):
|
|
|
|
server_liste, user_liste = [] , []
|
|
|
|
server_liste, user_liste = [] , []
|
|
|
|
for row in read_server:
|
|
|
|
for row in read_server:
|
|
|
|
user_liste.append(row['user'])
|
|
|
|
user_liste.append(row['user'])
|
|
|
|
server_liste.append(row['\ufeffserver'])
|
|
|
|
server_liste.append(row['\ufeffserver'])
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'server' : server_liste,
|
|
|
|
'server' : server_liste,
|
|
|
|
'user' : user_liste
|
|
|
|
'user' : user_liste
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ssh_connection(con_server = str):
|
|
|
|
def ssh_connection(con_server = str, bash_script = """ls -lisaR /home; apt list --installed"""):
|
|
|
|
with Popen(['ssh', '-T', con_server],
|
|
|
|
with Popen(['ssh', '-T', con_server],
|
|
|
|
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
|
|
|
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
|
|
|
universal_newlines=True) as p:
|
|
|
|
universal_newlines=True) as p:
|
|
|
|
output, error = p.communicate("""
|
|
|
|
output, error = p.communicate(bash_script)
|
|
|
|
ls -lisaR /home
|
|
|
|
|
|
|
|
apt list --installed
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
print(output)
|
|
|
|
print(output)
|
|
|
|
print(error)
|
|
|
|
print(error)
|
|
|
|
print(p.returncode)
|
|
|
|
print(p.returncode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ssh_check(con_server = str, check_port = 22):
|
|
|
|
|
|
|
|
response = os.system("ping -c 1 " + con_server + '>& /dev/null')
|
|
|
|
|
|
|
|
if response == 0:
|
|
|
|
|
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
|
|
|
|
|
|
return s.connect_ex((con_server, check_port)) == 0
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
for count in range(0,len(read_csv("test.csv")['server'])):
|
|
|
|
script_folder = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
print("Server:", read_csv("test.csv")['server'][count], "User:", read_csv("test.csv")['user'][count], sep=" ")
|
|
|
|
server_csv = script_folder + os.sep + "test.csv"
|
|
|
|
ssh_connection(con_server=read_csv("test.csv")['server'][count])
|
|
|
|
|
|
|
|
|
|
|
|
for count in range(0,len(read_csv(server_csv)['server'])):
|
|
|
|
|
|
|
|
servername = read_csv(server_csv)['server'][count]
|
|
|
|
|
|
|
|
print(servername, "verbindng wird geprüft...",sep=' ')
|
|
|
|
|
|
|
|
if ssh_check(con_server=servername) is True:
|
|
|
|
|
|
|
|
print(servername, "erreichbar...", sep=' ')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print(servername, "nicht erreichbar oder kein ssh!!", sep=' ')
|
|
|
|
|
|
|
|
#if ssh_check(con_server=servername) is True:
|
|
|
|
|
|
|
|
# print(servername, "port offen")
|
|
|
|
|
|
|
|
#print("Server:", read_csv(server_csv)['server'][count], "User:", read_csv(server_csv)['user'][count], sep=" ")
|
|
|
|
|
|
|
|
#ssh_connection(con_server=read_csv("test.csv")['server'][count])
|
|
|
|
|
|
|
|
|
|
|
|
|