Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from bittentech/master
Browse files Browse the repository at this point in the history
ASN-Eagle will now work on arguments passed onto it.
  • Loading branch information
ritiksahni authored Feb 21, 2020
2 parents b67a602 + 672c017 commit be3d069
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
64 changes: 49 additions & 15 deletions ASN-Eagle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import terminal_banner
from termcolor import colored
import os
import argparse

os.system('clear')

Expand All @@ -25,42 +26,75 @@
Instagram: https://www.instagram.com/deep.tech
""")


# Print Banner for ASN-Eagle
banner_terminal = terminal_banner.Banner(banner_text)
print (colored(banner_terminal, 'cyan'))

help = 'python3 ASN-Eagle.py -d domain [OPTIONS]\nOPTIONS:\n\n-i\t--ip-range\tDiscover Netblocks/IP ranges\n-o\t--output-file\tWrite output to a file\n'

arg_parse = argparse.ArgumentParser(usage=help)
arg_parse.add_argument('-d','--domain',required=True)
arg_parse.add_argument('-i','--ip-ranges', default=False, action='store_const',const = 1)
arg_parse.add_argument('-o','--output-file')
args = arg_parse.parse_args()

# Fetch IP address of website using socket and save it to a variable
hostname = input(colored("Enter hostname [e.g google.com, tesla.com]: ", 'green'))
hostname = args.domain
ip_addr = socket.gethostbyname(hostname)

print(colored("Fetching AS Number..\n", 'white'))

# Extract ASN using ipinfo API.
asn_fetch = requests.get('https://ipinfo.io/'+ip_addr+'/org?token=c8bb8b5ed87127')

print(colored("ASN Details found!!\n\n"+asn_fetch.text, 'magenta')) # Print ASN details
access_rights = (0o755) # Defining access rights for creating output directory.
#fetch the desired result and store it
discovered_asn = asn_fetch.text

prompt1 = input(colored("\n\nDo you want to scan for IP ranges from discovered ASN? (Y or N)\n", 'green')) # Prompt for IP ranges
print(colored("[+] ASN Details found!!\n", 'magenta')) # Print ASN details
print(colored(discovered_asn , 'yellow'))
access_rights = (0o755) # Defining access rights for creating output directory.

path = ("./output")

if prompt1 == "Y": # If-elif for saving IP ranges functionality.
if(args.ip_ranges == 1):

#fetch the AS Number from the previous output
new_asn = discovered_asn.split(' ')[0]

print(colored("Fetching IP ranges belonging to the AS..\n", 'white'))

try:
discovered_asn = input(colored('Enter the discovered ASN: ', 'green'))
result = requests.get('https://api.hackertarget.com/aslookup/?q='+discovered_asn) # Makes request to fetch IP RANGE LIST.
result = requests.get('https://api.hackertarget.com/aslookup/?q='+new_asn) # Makes request to fetch IP RANGE LIST.
print(colored("[+] IP ranges found!!\n", 'magenta'))
print(result.text+'\n')

except Exception:
print("Invalid ASN!")
filename = input(colored("\nEnter the filename for saving the results [e.g. results.txt] : ", 'blue'))
print("There is something wrong.")


if(args.output_file != None):

filename = args.output_file

try: # Creates 'output/' directory and file to save result containing IP ranges.
os.mkdir(path, access_rights)

except OSError:
print(colored("Output directory already exists, creating file with IP ranges!", 'green'))

file = open("./output/"+filename, "w")

try:
file.write(result.text)
print (colored("\n\nResults saved in output/"+filename, 'blue'))
if(args.ip_ranges == 1):
file.write(result.text+'\n') #write the result with ip ranges in the file
else:
file.write(discovered_asn+'\n') #write the result without ip ranges in the file
print (colored("\nResults saved in output/"+filename+'\n', 'blue'))

except Exception:
print (colored("Task failed! Try again!", 'red'))
elif prompt1 == "N":
sys.exit
else:
print (colored("Invalid input!", 'red'))




3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
requests
sockets
terminal_banner
termcolor
termcolor
argparse

0 comments on commit be3d069

Please sign in to comment.