lundi 18 mars 2019

Select Working Domain Using Bash and Curl

I am trying to find a domain that is working and use it but, ideally a randomly selected domain. Right now it just seems to only use the last domain in the if statement. What can i do to change this and instead use randomly selected domain. Thanks

#!/bin/bash

One() {
    ip=$(curl https://ipapi.co/ip)
    country=$(curl https://ipapi.co/$ip/country/)
    echo $ip - $country 1
}

Two() {
    ip=$(curl https://api.db-ip.com/v2/free/self/ipAddress)
    country=$(curl https://api.db-ip.com/v2/free/$ip/countryCode)
    echo $ip - $country 2
}

Three() {
    ip=$(curl https://api.ipdata.co/ip?api-key=test)
    country=$(curl https://api.ipdata.co/$ip/country_code?api-key=test)
    echo $ip - $country 3
}


Fore() {
    ip=$(curl http://api.ipaddress.com/myip)
    country=$(curl -s http://api.ipaddress.com/iptocountry)
    echo $ip - $country 4
}

if curl -k --max-time 10 --head --request GET https://ipapi.co/ip | grep "200 OK" > /dev/null; then
        One
    elif curl -k --max-time 10 --head --request GET https://api.db-ip.com/v2/free/self/ipAddress | grep "200 OK" > /dev/null; then
        Two
    elif curl -k --max-time 10 --head --request GET https://api.ipdata.co/ip?api-key=test | grep "200 OK" > /dev/null; then
        Three
    elif curl -k --max-time 10 --head --request GET http://api.ipaddress.com/iptocountry | grep "200 OK" > /dev/null; then
        Fore
    else
        echo
fi

Aucun commentaire:

Enregistrer un commentaire