|
| 1 | +# Import the necessary libraries |
| 2 | +import argparse |
| 3 | +import ipaddress |
| 4 | +import socket |
| 5 | +import requests |
| 6 | + |
| 7 | +API_KEY = "Your-Api-Key-Here" # Replace with your ViewDNS API key |
| 8 | + |
| 9 | +# Function to Check if IP address is valid. |
| 10 | +def is_valid_ip(ip): |
| 11 | + |
| 12 | + try: |
| 13 | + ipaddress.ip_address(ip) |
| 14 | + return True |
| 15 | + except ValueError: |
| 16 | + return False |
| 17 | + |
| 18 | + |
| 19 | +# Perform reverse look up. |
| 20 | +def reverse_lookup(ip): |
| 21 | + try: |
| 22 | + domain = socket.gethostbyaddr(ip)[0] |
| 23 | + return domain |
| 24 | + except socket.herror: |
| 25 | + return None |
| 26 | + |
| 27 | + |
| 28 | +# Get websites on same server. |
| 29 | +def get_websites_on_server(ip): |
| 30 | + url = f"https://api.viewdns.info/reverseip/?host={ip}&apikey={API_KEY}&output=json" |
| 31 | + response = requests.get(url) |
| 32 | + if response.status_code == 200: |
| 33 | + data = response.json() |
| 34 | + if "response" in data and "domains" in data["response"]: |
| 35 | + websites = data["response"]["domains"] |
| 36 | + return websites |
| 37 | + return [] |
| 38 | + |
| 39 | + |
| 40 | +# Get user arguments and execute. |
| 41 | +def main(): |
| 42 | + parser = argparse.ArgumentParser(description="Perform IP reverse lookup.") |
| 43 | + parser.add_argument("ips", nargs="+", help="IP address(es) to perform reverse lookup on.") |
| 44 | + parser.add_argument("--all", "-a", action="store_true", help="Print all other websites on the same server.") |
| 45 | + args = parser.parse_args() |
| 46 | + |
| 47 | + for ip in args.ips: |
| 48 | + if not is_valid_ip(ip): |
| 49 | + print(f"[-] Invalid IP address: {ip}") |
| 50 | + continue |
| 51 | + |
| 52 | + domain = reverse_lookup(ip) |
| 53 | + if domain: |
| 54 | + print(f"[+] IP: {ip}, Domain: {domain}") |
| 55 | + if args.all: |
| 56 | + websites = get_websites_on_server(ip) |
| 57 | + if websites: |
| 58 | + print("\nOther websites on the same server:") |
| 59 | + for website in websites: |
| 60 | + print(f"[+] {website}") |
| 61 | + print('\n') |
| 62 | + else: |
| 63 | + print("[-] No other websites found on the same server.") |
| 64 | + else: |
| 65 | + print(f"[-] No domain found for IP: {ip}") |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + main() |
0 commit comments