2 ##############################################################################
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as
6 # published by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # Copyright (C) 2016 Eric Luehrsen
15 ##############################################################################
17 # These are iptools that might be useful in a larger package, if provided
18 # elsewhere for common use. One example that many may find useful is turning
19 # flexible IPV6 colon dividers into PTR. Otherwise these are incomplete and
20 # would need robustness improvements for more generic applications.
22 ##############################################################################
25 # Get the nibble rounded /CIDR ...ip6.arpa.
31 sub(/\/[0-9]+/,"",$0) ;
33 for(i=1; i<=NF; i++) {
35 for(j=1; j<=ct_stop; j++) { $i = ($i "0000") ; } }
36 else { $i = substr(("0000" $i), length($i)+5-4) ; } } ;
38 ct_start = length(y) - 32 + CIDR ;
39 for(i=ct_start; i>0; i--) { x = (x substr(y,i,1)) ; } ;
45 ##############################################################################
48 # Get complete host ...ip6.arpa.
51 { sub(/\/[0-9]+/,"",$0) ;
53 for(i=1; i<=NF; i++) {
55 for(j=1; j<=ct_stop; j++) { $i = ($i "0000") ; } }
56 else { $i = substr(("0000" $i), length($i)+5-4) ; } } ;
59 for(i=ct_start; i>0; i--) { x = (x substr(y,i,1)) ; } ;
60 sub(/[0-9]+\//,"",x) ;
66 ##############################################################################
69 # Get the byte rounded /CIDR ...in-addr.arpa.
76 split(dtxt, dtxt, ".") ;
77 for(i=1; i<=CIDR; i++) { x = (dtxt[i] "." x) ; }
78 x = (x "in-addr.arpa") ;
82 ##############################################################################
85 # Get omplete host ...in-addr.arpa.
87 '{ x = ( $4"."$3"."$2"."$1".in-addr.arpa" ) ;
88 sub(/\/[0-9]+/,"",x) ;
92 ##############################################################################
97 [1-9][0-9a-f][0-9a-f][0-9a-f]":"*) echo "ok" ;;
99 f[cd][0-9a-f][0-9a-f]":"*) echo "ok" ;;
100 # fe80::, ::1, and such
105 ##############################################################################
109 # Link, Local, and Such
110 169"."254"."*) echo "not" ;;
111 127"."*) echo "not" ;;
113 255"."*) echo "not" ;;
115 25[0-4]"."[0-9]*) echo "ok" ;;
116 2[0-4][0-9]"."[0-9]*) echo "ok" ;;
117 1[0-9][0-9]"."[0-9]*) echo "ok" ;;
118 [0-9][0-9]"."[0-9]*) echo "ok" ;;
119 [0-9]"."[0-9]*) echo "ok" ;;
125 ##############################################################################
129 local validip4=$( valid_subnet4 $subnet )
130 local validip6=$( valid_subnet6 $subnet )
133 if [ "$validip4" = "ok" ] || [ "$validip6" = "ok" ] ; then
139 ##############################################################################
144 172"."1[6-9]"."*) echo "ok" ;;
145 172"."2[0-9]"."*) echo "ok" ;;
146 172"."3[0-1]"."*) echo "ok" ;;
147 192"."168"."*) echo "ok" ;;
148 f[cd][0-9a-f][0-9a-f]":"*) echo "ok" ;;
153 ##############################################################################
157 local arpa validip4 validip6
159 validip4=$( valid_subnet4 $subnet )
160 validip6=$( valid_subnet6 $subnet )
163 if [ "$validip4" = "ok" ] ; then
164 arpa=$( domain_ptr_ip4 "$subnet" )
165 elif [ "$validip6" = "ok" ] ; then
166 arpa=$( domain_ptr_ip6 "$subnet" )
170 if [ -n "$arpa" ] ; then
175 ##############################################################################
179 local arpa validip4 validip6
181 validip4=$( valid_subnet4 $subnet )
182 validip6=$( valid_subnet6 $subnet )
185 if [ "$validip4" = "ok" ] ; then
186 arpa=$( host_ptr_ip4 "$subnet" )
187 elif [ "$validip6" = "ok" ] ; then
188 arpa=$( host_ptr_ip6 "$subnet" )
192 if [ -n "$arpa" ] ; then
197 ##############################################################################