ASN Details
Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’.
Short Description
This script adds a cli tool (in python) to quickly look up autonomous systems by number or name.
Problem solved by this Code Snippet
Not a problem per se, but makes information retrieval easier by not requiring a browser session looking up information.
How to use this Code Snippet
(venv) me@macos scripts % python asn_info.py -a f5
22317 = F5-NETWORKS
209077 = NEWTON-AS D8C2 59FB C6DE 0B2B D56B EAF9 3CF5 EA56 759A E33D
268951 = F5 INFORMATICA COMERCIO DE PRODUTOS ELETRONICOS LT
398349 = F5-SILVERLINE-LABS
(venv) me@macos scripts % python asn_info.py -n 22317
22317 = F5-NETWORKS
Code Snippet Meta Information
- Version: 0.1
- Coding Language: python
Full Code Snippet
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)
Published Jun 08, 2022
Version 1.0JRahm
Admin
Christ Follower, Husband, Father, Technologist. I love community and I especially love THIS community. My background is networking, but I've dabbled in all the F5 iStuff, I'm a recovering Perl guy, and am very much a python enthusiast. Learning alongside all of you in this accelerating industry toward modern apps and architectures.No CommentsBe the first to comment
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)