check_ip.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # LGSM check_ip.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Automatically identifies the server interface IP.
  6. # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
  7. local commandnane="CHECK"
  8. local commandaction="Checking"
  9. local selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. if [ "${gamename}" != "Teamspeak 3" ]; then
  11. if [ ! -f "/bin/ip" ]; then
  12. ipcommand="/sbin/ip"
  13. else
  14. ipcommand="ip"
  15. fi
  16. getip=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
  17. getipwc=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
  18. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  19. if [ "${getipwc}" -ge "2" ]; then
  20. fn_print_fail "Multiple active network interfaces found.\n\n"
  21. echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
  22. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  23. echo -en "${getip}\n"
  24. echo -en ""
  25. echo -en "https://gameservermanagers.com/network-interfaces\n"
  26. echo -en ""
  27. fn_script_log_fatal "Multiple active network interfaces found."
  28. fn_script_log_fatal "Manually specify the IP you want to use within the ${selfname} script."
  29. fn_script_log_fatal "https://gameservermanagers.com/network-interfaces\n"
  30. core_exit.sh
  31. else
  32. ip=${getip}
  33. fi
  34. fi
  35. fi