-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathip_check_ipv4.sh
executable file
·46 lines (41 loc) · 1.38 KB
/
ip_check_ipv4.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#-----------------------------------------------------------------------
#
# Basescript function
#
# The basescript functions were designed to work as abstract function,
# so it could be used in many different contexts executing specific job
# always remembering Unix concept DOTADIW - "Do One Thing And Do It Well"
#
# Developed by
# Evert Ramos <evert.ramos@gmail.com>
#
# Copyright Evert Ramos
#
#-----------------------------------------------------------------------
#
# Be careful when editing this file, it is part of a bigger script!
#
# Basescript - https://github.com/evertramos/basescript
#
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# This function has one main objective:
# 1. Check if the IPv4 is a valid address
#
# You must/might inform the parameters below:
# 1. IP address that should be checked
# 2. [optional] (default: ) n/a
#
#-----------------------------------------------------------------------
ip_check_ipv4()
{
local LOCAL_IP_ADDRESS
LOCAL_IP_ADDRESS=${1:-null}
# Check required
[[ $LOCAL_IP_ADDRESS == "" || $LOCAL_IP_ADDRESS == null ]] && echoerror "You must inform the required argument(s) to the function: '${FUNCNAME[0]}'"
if [[ $LOCAL_IP_ADDRESS =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
IP_IPV4=true
else
IP_IPV4=false
fi
}