fn_autoip 751 B

12345678910111213141516171819202122
  1. #!/bin/bash
  2. # LGSM fn_autoip function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 011214
  6. # Identifies the server interface IP
  7. # If multiple interfaces this will need to be set manually
  8. getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
  9. getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
  10. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  11. if [ "${getipwc}" -ge "2" ]; then
  12. fn_printwarn "Multiple active network interfaces.\n\n"
  13. echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
  14. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  15. echo -en "${getip}\n"
  16. exit
  17. else
  18. ip=${getip}
  19. fi
  20. fi