Browse Source

feat: add country code of external IP address

This commit adds functionality to retrieve the country code of the external IP address. If the country code is not already stored in a file, it uses curl to fetch it from https://ipapi.co/country and saves it in "${tmpdir}/countrycode.txt". If curl fails, an error message is displayed.
pull/4295/head
Daniel Gibbs 2 years ago
parent
commit
ac7f9fdfa3
  1. 14
      lgsm/modules/info_game.sh

14
lgsm/modules/info_game.sh

@ -2397,6 +2397,20 @@ else
extip="$(cat "${tmpdir}/extip.txt")" extip="$(cat "${tmpdir}/extip.txt")"
fi fi
# Country code of external IP address
if [ ! -f "${tmpdir}/countrycode.txt" ]; then
countrycode="$(curl --connect-timeout 10 -s https://ipapi.co/country 2> /dev/null)"
exitcode=$?
# if curl passes add extip to externalip.txt
if [ "${exitcode}" == "0" ]; then
echo "${countrycode}" > "${tmpdir}/countrycode.txt"
else
echo "Unable to get external IP address"
fi
else
countrycode="$(cat "${tmpdir}/countrycode.txt")"
fi
# Alert IP address # Alert IP address
if [ "${displayip}" ]; then if [ "${displayip}" ]; then
alertip="${displayip}" alertip="${displayip}"

Loading…
Cancel
Save