_ak_network_utils
1 #!/usr/bin/env bash 2 ### 3 ### arching-kaos-tools 4 ### Tools to interact and build an Arching Kaos Infochain 5 ### Copyright (C) 2021 - 2026 kaotisk 6 ### 7 ### This program is free software: you can redistribute it and/or modify 8 ### it under the terms of the GNU General Public License as published by 9 ### the Free Software Foundation, either version 3 of the License, or 10 ### (at your option) any later version. 11 ### 12 ### This program is distributed in the hope that it will be useful, 13 ### but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ### GNU General Public License for more details. 16 ### 17 ### You should have received a copy of the GNU General Public License 18 ### along with this program. If not, see <http://www.gnu.org/licenses/>. 19 ### 20 source $AK_LIBDIR/_ak_lib_load 21 _ak_lib_load _ak_log 22 _ak_lib_load _ak_datetime 23 24 ## 25 # Copied from http://y.yggdrasil-network.ca/yia/crawler/crawler-yia.sh made by 26 # ircerr 27 # 28 # Changes: 29 # - name of function from padip to _ak_network_utils_pad_ip 30 # 31 function _ak_network_utils_pad_ip() { #Pad IP - fill in missing zeros 32 ip=$1 33 if [ "$ip" == "" ]; then return; fi 34 PADIP="" 35 if [ "`echo \"$ip\"|grep '::'`" != "" ] 36 then 37 CC="$((`echo \"$ip\"|sed 's/:://g'|tr ':' '\n'|wc -l`))" #count cols 38 if [ "$CC" != "8" ] 39 then 40 NC=$((7-$CC)) 41 RS="" 42 for X in `seq 1 $NC` 43 do 44 if [ "$RS" == "" ] 45 then 46 RS="0000" 47 else 48 RS="$RS:0000" 49 fi 50 done 51 ip="`echo \"$ip\"|sed \"s/\:\:/\:$RS\:/g\"`" 52 fi 53 fi 54 SEGIP="`echo $ip|tr ':' ' '`" 55 for S in $SEGIP 56 do 57 while : 58 do 59 if [ "`echo $S|cut -b 4`" == "" ] 60 then 61 S="0$S" 62 continue 63 fi 64 if [ "$PADIP" == "" ] 65 then 66 PADIP="$S" 67 else 68 PADIP="$PADIP:$S" 69 fi 70 break 71 done 72 done 73 if [ "$PADIP" != "" ] 74 then 75 ip="$PADIP" 76 fi 77 echo "$ip" 78 return 79 } 80 81 _ak_log_debug "_ak_network_utils loaded $(caller)"