0% found this document useful (0 votes)
59 views3 pages

Advanced IP Fetching Tool Guide

Uploaded by

lewiroc511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views3 pages

Advanced IP Fetching Tool Guide

Uploaded by

lewiroc511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

This conversation was generated with DuckDuckGo AI Chat (https://duck.

ai) using
OpenAI's GPT-4o mini Model. AI chats may display inaccurate or offensive
information (see https://duckduckgo.com/aichat/privacy-terms for more info).

====================

User prompt 1 of 1 - 12/17/2024, 3:52:54 AM:


import requests
import aiohttp
import asyncio
import pandas as pd
from colorama import Fore, Style
from rich.console import Console
from rich.table import Table
from rich.prompt import Prompt
from rich.progress import Progress
from rich import print
import re
import time

console = Console()

# ASCII Art for the tool


ascii_art = r"""
____ _ _ _____ _
| _ \| | | | | __ \ | |
| |_) | | ___ ___| |__ __ _| | | | ___ ___| |_ ___
| _ <| |/ _ \/ __| '_ \ / _` | | | |/ _ \/ __| __/ _ \
| |_) | | __/ (__| | | | (_| | |__| | __/ (__| || __/
|____/|_|\___|\___|_| |_|\__,_|_____/ \___|\___|\__\___|
"""

class IPFetcher:
def __init__(self):
self.ip_info_url = "https://ipinfo.io/{}/json"
self.public_ip_url = "https://api.ipify.org"
self.console = Console()

def get_public_ip(self):
try:
response = requests.get(self.public_ip_url)
response.raise_for_status()
return response.text
except requests.RequestException as e:
console.print(f"{Fore.RED}Error fetching public IP: {e}
{Style.RESET_ALL}")
return None

def validate_ip(self, ip_address):


pattern = re.compile(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$')
return pattern.match(ip_address) is not None

async def fetch_ip_info(self, session, ip_address):


try:
async with session.get(self.ip_info_url.format(ip_address)) as
response:
response.raise_for_status()
return await response.json()
except Exception as e:
console.print(f"{Fore.RED}Error fetching IP info for {ip_address}: {e}
{Style.RESET_ALL}")
return None

async def fetch_multiple_ips(self, ip_list):


async with aiohttp.ClientSession() as session:
tasks = [self.fetch_ip_info(session, ip) for ip in ip_list]
return await asyncio.gather(*tasks)

def display_ip_info(self, ip_info):


if ip_info:
table = Table(title="IP Information", border="round")
for key, value in ip_info.items():
table.add_column(key, justify="left", style="cyan", no_wrap=True)
table.add_row(str(value))
console.print(table)
if 'loc' in ip_info:
console.print(f"{Fore.GREEN}Map: https://www.google.com/maps?
q={ip_info['loc']}{Style.RESET_ALL}")
else:
console.print(f"{Fore.YELLOW}No information available.
{Style.RESET_ALL}")

def save_to_csv(self, results):


df = pd.DataFrame(results)
df.to_csv('ip_info_results.csv', index=False)
console.print(f"{Fore.GREEN}Results saved to
ip_info_results.csv{Style.RESET_ALL}")

def animate_loading(self):
with Progress() as progress:
task = progress.add_task("[cyan]Fetching IP info...", total=100)
for _ in range(100):
time.sleep(0.05) # Simulate work being done
progress.update(task, advance=1)

def run(self):
console.print(ascii_art)
console.print(f"{Fore.BLUE}Welcome to the Advanced IP Fetching Tool!
{Style.RESET_ALL}")
public_ip = self.get_public_ip()
if public_ip:
console.print(f"{Fore.CYAN}Your Public IP: {public_ip}
{Style.RESET_ALL}")

ip_list = [public_ip]
while True:
user_input = Prompt.ask("Enter additional IP addresses (comma-
separated) or type 'done' to finish")
if user_input.lower() == 'done':
break
for ip in user_input.split(','):
ip = ip.strip()
if self.validate_ip(ip):
ip_list.append(ip)
else:
console.print(f"{Fore.RED}Invalid IP format: {ip}
{Style.RESET_ALL}")
console.print(f"{Fore.YELLOW}Fetching information for {len(ip_list)}
IP(s)...{Style.RESET_ALL}")
self.animate_loading() # Show loading animation
results = asyncio.run(self.fetch_multiple_ips(ip_list))

replace with ascii artanother ascii art

GPT-4o mini:
Certainly! Below is an alternative ASCII art that you can use to replace the
existing one in your code:

```python
ascii_art = r"""
_ _ _ _ _____ _
| | | (_) | | | __ \ | |
| | | |_ _ __ __ _| |__ __ _| | | | ___ ___| |_ ___
| | | | | '__/ _` | '_ \ / _` | | | |/ _ \/ __| __/ _ \
| |__| | | | | (_| | | | | (_| | |__| | __/ (__| || __/
\____/|_|_| \__, |_| |_|\__,_|_____/ \___|\___|\__\___|
__/ |
|___/
"""
```

To implement this, simply replace the existing `ascii_art` variable in your code
with the new one provided above. The rest of your code will remain unchanged.

You might also like