Last active
May 23, 2021 06:22
-
-
Save nitesh8860/defb28d5f08158bae16c42ff9c2908c0 to your computer and use it in GitHub Desktop.
script tests if there is a connection between source IP, dest IP and dest port. it requires a central server which is able to login to all source servers. (ansible master).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Example format for sdp.csv file. | |
source,dest,port | |
10.0.x.x,10.0.x.y,80 | |
10.0.x.x,10.0.x.y,800 | |
''' | |
import csv | |
import base64 | |
import paramiko | |
with open('sdp.csv','r') as data_file: | |
csv_data = csv.DictReader(data_file) | |
#next(csv_data) | |
for line in csv_data: | |
try: | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect(line.get('source'), username='<username>', password='<password>') | |
stdin,stdout,stderr= ssh.exec_command('echo \'exit\' | telnet {} {}'.format(line.get('dest'), line.get('port'))) | |
print('Source: {}, Destination: {}, Port: {}, Status: {}'.format(line.get('source'),line.get('dest'),line.get('port'),stdout.readlines()[1])) | |
ssh.close() | |
except IndexError: | |
print('Source: {}, Destination: {}, Port: {}, Status: {}'.format(line.get('source'),line.get('dest'),line.get('port'),"Connection not available or Dest app down")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment