Created
February 24, 2019 05:10
-
-
Save dpetzold/46a2c3778f8acf6213f3c03d49c259ad to your computer and use it in GitHub Desktop.
Find a ElasticLoadBalancer (ELB) by its ip address
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
import boto3 | |
import socket | |
import argparse | |
client = boto3.client('elb') | |
def find_elb_by_ip(ip): | |
paginator = client.get_paginator('describe_load_balancers') | |
response_iterator = paginator.paginate() | |
for response in response_iterator: | |
for lb in response['LoadBalancerDescriptions']: | |
ips = socket.gethostbyname_ex(lb['DNSName']) | |
if ip in ips[2]: | |
print(lb['DNSName']) | |
break | |
def main(): | |
parser = argparse.ArgumentParser(description='Process some integers.') | |
parser.add_argument('ip', help='The ELBs ip') | |
args = parser.parse_args() | |
find_elb_by_ip(args.ip) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment