check_ip.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # LinuxGSM check_ip.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Automatically identifies the server interface IP.
  6. # If multiple interfaces are detected the user will need to manually set using ip="0.0.0.0".
  7. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. info_config.sh
  9. info_parms.sh
  10. if [ ! -f "/bin/ip" ]; then
  11. ipcommand="/sbin/ip"
  12. else
  13. ipcommand="ip"
  14. fi
  15. getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
  16. getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -vc 127.0.0)
  17. # Check if server has multiple IP addresses
  18. # If the IP variable has been set by user.
  19. if [ -n "${ip}" ]&&[ "${ip}" != "0.0.0.0" ]; then
  20. queryips=( "${ip}" )
  21. # If game config does have an IP set.
  22. elif [ -n "${configip}" ]&&[ "${configip}" != "0.0.0.0" ];then
  23. queryips=( "${configip}" )
  24. ip="${configip}"
  25. # If no ip is set by the user.
  26. else
  27. queryips=( $(echo "${getip}") )
  28. ip="0.0.0.0"
  29. # If IP has not been set by user.
  30. fi