fn_check_ip 992 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. # LGSM fn_check_ip function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. # Version: 170415
  6. # Description: Automatically identifies the server interface IP.
  7. # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
  8. if [ ! -f /bin/ip ]; then
  9. ipcommand="/sbin/ip"
  10. else
  11. ipcommand="ip"
  12. fi
  13. getip=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
  14. getipwc=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
  15. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  16. if [ "${getipwc}" -ge "2" ]; then
  17. fn_printwarn "Multiple active network interfaces found.\n\n"
  18. echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
  19. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  20. echo -en "${getip}\n"
  21. echo -en ""
  22. echo -en "http://gameservermanagers.com/network-interfaces"
  23. exit
  24. else
  25. ip=${getip}
  26. fi
  27. fi