fn_autoip 865 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. # LGSM fn_autoip function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 010115
  6. # Description: Identifies the server interface IP.
  7. # If multiple interfaces this will need to be set manually.
  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. exit
  22. else
  23. ip=${getip}
  24. fi
  25. fi