check_ip.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # LinuxGSM check_ip.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Automatically identifies the server interface IP.
  7. # If multiple interfaces are detected the user will need to manually set using ip="0.0.0.0".
  8. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. info_config.sh
  10. info_parms.sh
  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\}' | sort -u | grep -v 127.0.0)
  17. getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -vc 127.0.0)
  18. # Check if server has multiple IP addresses
  19. # If the IP variable has been set by user.
  20. if [ -n "${ip}" ]&&[ "${ip}" != "0.0.0.0" ]; then
  21. queryips=( "${ip}" )
  22. webadminip=( "${ip}" )
  23. telnetip=( "${ip}" )
  24. # If game config does have an IP set.
  25. elif [ -n "${configip}" ]&&[ "${configip}" != "0.0.0.0" ];then
  26. queryips=( "${configip}" )
  27. ip="${configip}"
  28. webadminip=( "${configip}" )
  29. telnetip=( "${configip}" )
  30. # If there is only 1 server IP address.
  31. # Some IP details can automaticly use the one IP
  32. elif [ "${getipwc}" == "1" ]; then
  33. queryips=( $(echo "${getip}") )
  34. ip="0.0.0.0"
  35. webadminip=( "${getip}" )
  36. telnetip=( "${getip}" )
  37. # If no ip is set by the user and server has more than one IP.
  38. else
  39. queryips=( $(echo "${getip}") )
  40. ip="0.0.0.0"
  41. webadminip=( "${ip}" )
  42. telnetip=( "${ip}" )
  43. fi