#!/bin/bash

# API URL for querying IP location https://ip.zxinc.org/api.php?type=json&ip=
API_URL="http://ip.mir6.com/api/api_json.php?ip="

query_ip_location() {
    local ip=$1
    # Fetch the JSON response from the API
    local response=$(curl -s "$API_URL$ip&token=mir6.com")
    
    # Extract country and city information using jq
    local country=$(echo "$response" | jq -r '.data.country')
    local isp=$(echo "$response" | jq -r '.data.isp')
    local location=$(echo "$response" | jq -r '.location')
    # Output the result
    echo "IP: $ip, $isp Location: $location"
}

# Read IPs from input and query their locations
while read -r ip; do
    query_ip_location "$ip"
done < /dev/stdin