Created
June 8, 2022 20:21
-
-
Save jasonrahm/d448f1ca06ee01d9b4a289d7bc2770c2 to your computer and use it in GitHub Desktop.
BGP ASN Info - credit to showipintbri
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 bgpstuff | |
import argparse | |
import re | |
def get_as_name(client, as_number): | |
client.get_as_name(as_number) | |
if client.status_code == 200 and client.exists: | |
print(f"{as_number} = {c.as_name}") | |
def get_as_number(client, as_name): | |
client.get_as_names() | |
all_names = client.all_as_names | |
re_string = f".*{as_name}.*" | |
re_params = re.compile(re_string, re.IGNORECASE) | |
for i in sorted(all_names): | |
name = all_names[i] | |
try: | |
m = re_params.match(name) | |
if m is not None: | |
result = str(m.group()) | |
print(f"{i} = {result}") | |
except: | |
pass | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Lookup ASN Name by ASN Number.") | |
group = parser.add_mutually_exclusive_group(required=True) | |
group.add_argument( | |
"-a", | |
"--as_name", | |
metavar="ASN_NAME", | |
type=str, | |
action="store", | |
help="The string you want contained in the ASN Name.", | |
) | |
group.add_argument( | |
"-n", | |
"--as_num", | |
metavar="ASN", | |
type=int, | |
action="store", | |
help="The ASN Number you want to lookup.", | |
) | |
args = parser.parse_args() | |
c = bgpstuff.Client() | |
if args.as_num: | |
get_as_name(c, args.as_num) | |
elif args.as_name: | |
get_as_number(c, args.as_name) |
f5-rahm
commented
Jun 8, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment