Get IP Address Information using Python

mahabub.devs3
Mahabubur Rahman
Published on Oct, 20 2024 1 min read 0 comments
image

Write code as bellow - 

import os
import urllib.request as urllib2
import json

while True:
    ip = input("What is your target IP: ")
    url = "http://ip-api.com/json/"
    response = urllib2.urlopen(url + ip)
    data = response.read()
    values = json.loads(data)

    print("IP:" + values["query"])
    print("City:" + values["city"])
    print("ISP:" + values["isp"])
    print("Country:" + values["country"])
    print("Region:" + values["region"])
    print("Timezone:" + values["timezone"])
    break


Output :

What is your target IP: 182.160.100.145
IP:182.160.100.145
City:Dhaka
ISP:Aamra Networks Limited
Country:Bangladesh
Region:C
Timezone:Asia/Dhaka

 

0 Comments