| 12345678910111213141516171819202122232425262728 |
- #!/bin/bash
- # LGSM fn_check_ip function
- # Author: Daniel Gibbs
- # Website: http://danielgibbs.co.uk
- # Version: 210115
- # Description: Automatically identifies the server interface IP.
- # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
- if [ ! -f /bin/ip ]; then
- ipcommand="/sbin/ip"
- else
- ipcommand="ip"
- fi
- getip=$(${ipcommand} -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
- getipwc=$(${ipcommand} -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
- if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
- if [ "${getipwc}" -ge "2" ]; then
- fn_printwarn "Multiple active network interfaces found.\n\n"
- echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
- echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
- echo -en "${getip}\n"
- exit
- else
- ip=${getip}
- fi
- fi
|