Browse Source

Fixed validip()

Issue where using multiple DNS servers would make the valid IP format checker conk out
master
Brandon Nolet 2 years ago
parent
commit
79016fba98
1 changed files with 13 additions and 17 deletions
  1. +13
    -17
      nmcli-basic.sh

+ 13
- 17
nmcli-basic.sh View File

@@ -27,7 +27,7 @@ function setstatic {

#Getting Static IP info
case $1 in #case to enable returnability
1)
conshow
setstatic 2
@@ -35,7 +35,7 @@ case $1 in #case to enable returnability
2)
read -p "Enter the desired IPv4 address: " IPAdd
echo
validip ${IPAdd} 2 3
validip 2 3 ${IPAdd}
;;
3)
read -p "Enter the IPv4 prefix length: " PrefLen
@@ -51,12 +51,12 @@ case $1 in #case to enable returnability
4)
read -p "Enter the default router/gateway IP: " GatewayIP
echo
validip ${GatewayIP} 4 5
validip 4 5 ${GatewayIP}
;;
5)
read -p "Enter the DNS server address(es): " DNSAdd
echo
validip ${DNSAdd} 5 6
validip 5 6 "${DNSAdd}"
;;

6)
@@ -92,12 +92,12 @@ function apply() {
}

function conshow() {
${NMCLI_BIN} con show

echo
read -p "Which interface to configure? " IntID
if [[ ${IntID} != '' ]]; then #empty strings make grep have a fit
nmcli -t con show | cut -d : -f 1 | grep ${IntID} &> /dev/null
if [[ $? != 0 ]]; then #checking for valid interface name being input
@@ -105,7 +105,7 @@ function conshow() {
echo "Sorry, that's not the name of a valid interface. Try again."
echo
sleep 1
conshow #would love to have a non-inception like way to do this.
else
#incomplete entry of interface results in completion by grep ;) Interesting I suppose
@@ -124,22 +124,18 @@ function conshow() {
}

function validip {
arg1=$(echo $1)
arg2=$(echo $2)
arg3=$(echo $3)
declare -i n
for i in "$1"; do
echo ${arg1} | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" > /dev/null
declare -i n=0
for i in $3; do
echo $i | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" > /dev/null
n=n+$?
done
if [ ${n} == 0 ]; then
echo ${arg2}
setstatic ${arg3}
setstatic $2
else
echo
echo "Sorry, that's not a valid IP. Try again."
echo
echo ${arg2}; setstatic ${arg2}
setstatic $1
fi

}
@@ -197,4 +193,4 @@ exit 0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# along with this program. If not, see <http://www.gnu.org/licenses/>

Loading…
Cancel
Save