-
Notifications
You must be signed in to change notification settings - Fork 5
/
disc_spider.py
42 lines (34 loc) · 1.33 KB
/
disc_spider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import aiohttp
import asyncio
async def get_ip_address_from_discord_id(discord_id: str) -> str:
"""
Function to retrieve the IP address associated with a Discord user ID.
Parameters:
- discord_id: str
The Discord user ID for which the IP address is to be fetched.
Returns:
- str
The IP address associated with the provided Discord user ID.
Raises:
- ValueError:
If the Discord ID is invalid or not found, an error is raised.
"""
# Discord API endpoint to fetch user data
url = f"https://discord.com/api/v9/users/{discord_id}"
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
if response.status == 200:
user_data = await response.json()
ip_address = user_data.get('ip', 'IP Address not found')
return ip_address
else:
raise ValueError(f"Failed to retrieve IP address. Status code: {response.status}")
async def main():
discord_id = input("Enter Discord user ID: ")
try:
ip_address = await get_ip_address_from_discord_id(discord_id)
print(f"The IP address associated with Discord ID {discord_id} is: {ip_address}")
except ValueError as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(main())