-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipchecksrx
73 lines (61 loc) · 3.09 KB
/
ipchecksrx
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
_author__ = 'MMahdy'
########################################################################################################################
######################This project aims to ease the extraction of zones, ###############################################
######################################### interfacesrelated to certain IPs from SRX ####################################
########################################################################################################################
#Import list
import paramiko
import csv
import getpass
from threading import Thread
import time
###################################################################################################################
################### Functions creation################################
####################################################################################################################
def Interface(k):
datain, dataout, dataerr = SRX.exec_command('show route forwarding-table matching ' + k + ' extensive | match "Next-hop interface" | trim 22')
return(dataout.read())
def Zone(y):
datain, dataout, dataerr = SRX.exec_command("show interface " + y + " | match zone | trim 20 ")
return(dataout.read())
##Function used to handle the device related info
def SRXinfoextract(x):
SourceIP = x
InterfaceList=[]
SourceInterface = Interface(x)
InterfaceList=SourceInterface.split()
if len(SourceInterface)==0:
print "Interface:"+"Null"+"\r\n"+"Zone:"+"Null"+"\r\n"
for i in InterfaceList:
if i.strip()=="fxp0.0":
print "Interface:"+i+"\r\n"+"Zone:"+"Null"+"\r\n"
else:
SourceZone = Zone(i)
print "Interface:"+i+"\r\n"+"Zone:"+SourceZone+"\r\n"
## Connection function
def fwconnect(l):
SRX.connect(l, username=UN, password=PWD)
print l
SRXinfoextract(ip)
SRX.close()
########################********************#############################**************###############################
########################################Program ********************* Program ########################################
########################********************#############################**************###############################
Check = 'Y'
UN = raw_input("Please enter the user name: ")
PWD = getpass.getpass("Please enter the password: ")
firewalls_list = raw_input("Please enter the path for the Devices file: ")
file = open(firewalls_list,"r")
IP_LIST = file.readlines()
IP_LIST = map(lambda s: s.strip(), IP_LIST)
global SRX
while Check == "Y":
ip = raw_input("Please enter the IP you want to check: ")
SRX = paramiko.SSHClient()
SRX.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for l in IP_LIST:
th1 = Thread(target=fwconnect, args=(l,))
th1.start()
time.sleep(5) ## This sleep to leave time for ssh communication
##if the delay is high in your network you can increase this sleep time
Check = raw_input("Do you want to check any other addresses(Y or N): ")