Created
November 15, 2023 08:41
-
-
Save random-robbie/bb0156295f7dcb9ef58e01e9f20bc33e to your computer and use it in GitHub Desktop.
Take a file called ips.txt and sort them by their PTR records
This file contains 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 socket | |
def get_hosting_platform(ip): | |
try: | |
reverse_dns = socket.gethostbyaddr(ip)[0] | |
if "amazon" in reverse_dns: | |
return "amazon" | |
elif "google" in reverse_dns: | |
return "google" | |
elif "azure" in reverse_dns: | |
return "azure" | |
elif "oracle" in reverse_dns: | |
return "oracle" | |
elif "ibm" in reverse_dns: | |
return "ibm" | |
else: | |
return reverse_dns | |
except: | |
return "other" | |
def write_to_file(file_name, ip): | |
with open(file_name, "a") as file: | |
file.write(ip) | |
file.write("\n") | |
def check_ips_from_file(file_name): | |
with open(file_name, "r") as file: | |
ips = file.readlines() | |
for ip in ips: | |
ip = ip.strip() | |
platform = get_hosting_platform(ip) | |
if platform == "amazon": | |
write_to_file("amazon.txt", ip) | |
print(f"{ip} is hosted on Amazon.") | |
elif platform == "google": | |
write_to_file("gcp.txt", ip) | |
print(f"{ip} is hosted on Google.") | |
elif platform == "azure": | |
write_to_file("azure.txt", ip) | |
print(f"{ip} is hosted on Azure.") | |
elif platform == "oracle": | |
write_to_file("oracle.txt", ip) | |
print(f"{ip} is hosted on oracle.") | |
elif platform == "oracle": | |
write_to_file("oracle.txt", ip) | |
print(f"{ip} is hosted on oracle.") | |
else: | |
write_to_file("other.txt", ""+ip+":"+platform+"") | |
print(f"{ip} is hosted on other platform.") | |
# Read IP addresses from the file and check them | |
check_ips_from_file("ips.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment