Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F117520565
ipv4-range
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
858 B
Referenced Files
None
Subscribers
None
ipv4-range
View Options
#!/bin/bash
# snippet from https://stackoverflow.com/questions/10768160/ip-address-converter
ip2dec
()
{
local
a
b
c
d
ip
=
$@
IFS
=
.
read
-r
a
b
c
d
<<<
"
$ip
"
printf
'%d\n'
"
$((
a
*
256
**
3
+
b
*
256
**
2
+
c
*
256
+
d
))
"
}
error_exit
()
{
echo
"Error:
$1
is not a valid IPv4 address range"
exit
1
}
# Only run this if there is a hypen present in $1
if
[[
"
$1
"
=
~
"-"
]]
;
then
# This only works with real bash (<<<) - split IP addresses into array with
# hyphen as delimiter
readarray
-d
-
-t
strarr
<<<
$1
ipaddrcheck
--is-ipv4-single
${
strarr
[0]
}
if
[
$?
-gt
0
]
;
then
error_exit
$1
fi
ipaddrcheck
--is-ipv4-single
${
strarr
[1]
}
if
[
$?
-gt
0
]
;
then
error_exit
$1
fi
start
=
$(
ip2dec
${
strarr
[0]
}
)
stop
=
$(
ip2dec
${
strarr
[1]
}
)
if
[
$start
-ge
$stop
]
;
then
error_exit
$1
fi
exit
0
fi
error_exit
$1
File Metadata
Details
Attached
Mime Type
text/x-shellscript
Expires
Sat, Sep 26, 11:10 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4283818
Default Alt Text
ipv4-range (858 B)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment