HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_new/buyercall/buyercall/blueprints/sysadmin/utilities/ip_api.py
import requests


def extract_ip(ip_list):
    ips = ip_list.split(',')  # Split the string by commas
    first_ip = ips[0].strip()  # Extract the first IP address and remove any leading or trailing whitespace
    return first_ip


class IpApi:

    @staticmethod
    def get_request_complete_details(ip_address):
        ip = extract_ip(ip_address)
        url = f"http://ip-api.com/json/{ip}?fields=status,message,country,regionName,city,zip,reverse"
        response = requests.get(url)

        if response.status_code == 200:
            data = response.json()
            return data if data.get('status') == "success" else {}

        return {}