-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdec2ip
executable file
·45 lines (40 loc) · 839 Bytes
/
dec2ip
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
#!/usr/bin/env bash
#set -o xtrace
source harden.sh
function dectoip {
echo "$1" | awk {'print rshift(and($1, 0xFF000000), 24) "." rshift(and($1,0x00FF0000), 16) "." rshift(and($1, 0x0000FF00), 8) "." and($1, 0x000000FF) '}
}
function hextoip {
dectoip "$(($1))"
}
NAME=$(basename $0)
case "$NAME" in
dec2ip)
FUNC="dectoip"
PREVAL=""
HELP="decimal number"
;;
hex2ip)
FUNC="hextoip"
PREVAL="0x"
HELP="hexadecimal number"
;;
*)
echo "I don't answer to the name $NAME" > /dev/stderr
exit 1;
;;
esac
if [ $# -eq 0 ]; then
while read VAL;
do $FUNC "$PREVAL$VAL"
done < /dev/stdin
else
if [[ "$1" != "-h" && "$1" != "--help" ]]; then
for VAL in "$@"
do $FUNC "$PREVAL$VAL"
done
else
echo "Usage: $NAME <$HELP> [<$HELP>...]"
echo " or : <source of ${HELP}s> | $NAME"
fi
fi;