瀏覽代碼

Changed tabs to spaces in SecurityGroup

Fred Damstra 9 年之前
父節點
當前提交
02db6e2425
共有 2 個文件被更改,包括 27 次插入1 次删除
  1. 26 0
      FindInstanceInProfile.py
  2. 1 1
      FindSecurityGroupInProfile.py

+ 26 - 0
FindInstanceInProfile.py

@@ -110,6 +110,32 @@ for region in regions:
 
 	continue	# Search next region by name
 
+# Search by IP
+for region in regions:
+	if DEBUG == 1:
+		print(".", end="")
+		sys.stdout.flush()
+	if DEBUG >= 2:
+		print("Searching by IP in region " + region + " in profile " + PROFILE)
+
+	ec2 = boto3.client('ec2', region_name=region)
+	try:
+		instance = ec2.describe_instances(Filters=[ {'Name': 'tag:ip-address', 'Values': [ SEARCHSTRING ] } ])
+	except:
+		print(str( sys.exc_info() ))
+
+	# Add to output
+	for r in instance['Reservations']:
+		for i in r['Instances']:
+			FOUND=FOUND+1
+			if DEBUG >= 2:
+				print("FOUND in profile '" + PROFILE + "', Region: '" + region + "'")
+			if FOUND > 1:
+				FOUNDSTR = FOUNDSTR + "\n"
+			FOUNDSTR = FOUNDSTR + "FOUND\t" + PROFILE + "\t" + region + "\t" + i['InstanceId']
+
+	continue	# Search next region by name
+
 # End of for region	
 if DEBUG == 1:
 	print(".")

+ 1 - 1
FindSecurityGroupInProfile.py

@@ -116,7 +116,7 @@ for region in regions:
 			print("FOUND in profile '" + PROFILE + "', Region: '" + region + "': ID=" + str(sg['SecurityGroups'][0]['GroupId']))
 		if FOUND > 1:
 			FOUNDSTR = FOUNDSTR + "\n"
-		FOUNDSTR = FOUNDSTR + "FOUND\t" + PROFILE + "\t" + region + "\t" + str(g['GroupId'])
+		FOUNDSTR = FOUNDSTR + PROFILE + " " + region + " " + str(g['GroupId'])
 	
 	continue	# Search next region by name