From ac7f9fdfa3c00c936f93055f883191ba5ad26699 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 14 Aug 2023 23:31:13 +0100 Subject: [PATCH] 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. --- lgsm/modules/info_game.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lgsm/modules/info_game.sh b/lgsm/modules/info_game.sh index 2bfdc10e7..5a7eb5942 100644 --- a/lgsm/modules/info_game.sh +++ b/lgsm/modules/info_game.sh @@ -2397,6 +2397,20 @@ else extip="$(cat "${tmpdir}/extip.txt")" 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 if [ "${displayip}" ]; then alertip="${displayip}"