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 {}