Skip to content

Instantly share code, notes, and snippets.

@nitesh8860
Last active May 23, 2021 06:22
Show Gist options
  • Save nitesh8860/defb28d5f08158bae16c42ff9c2908c0 to your computer and use it in GitHub Desktop.
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).
'''
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