Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to add string to end of each array element without loops



> On Mar 26,  3:37am, nix@xxxxxxxxxxxxxxxx wrote:
> }
> } Now however, im getting a segfault when an array elements exceeds over
> } 4 million elements even there are enough RAM in my box.
>
> A segfault doing what, exactly?  Perhaps run with:
>
> exec 2>/tmp/zsh$$trace
> setopt xtrace
>
> I can create and reference arrays of that size without a problem:
>
> schaefer<523> typeset -A a
> schaefer<524> a=({4000000..1} {1..4000000})
> schaefer<525> echo $#a
> 4000000
> schaefer<526> a=({5000000..1} {1..5000000})
> schaefer<527> echo $#a
> 5000000
>
> and then after noodling around a bit:
>
> schaefer<533> b=($a)
> schaefer<534> echo $#b
> 5000000
>
> even if I guarantee there are multiple simultaneous copies of the array:
>
> schaefer<535> foo() { local -a c; c=($b); print $#c }
> schaefer<536> foo
> 5000000
>
> so it's not something magic about 4 million.
>
> } Is there a way to increase this limit? There was nothing to that with
> } 'limit' command.
>
> The limit command (and ulimit) deal with OS-imposed limitations on the
> resource usage of a process.  It's entirely possible that it's one of
> those that you're running up against, but difficult to guess which one
> without knowing what the shell was doing at the moment of failure.
>
> Generally speaking zsh doesn't impose any of its own restrictions except
> for function recursion depth and number of simultaneous monitored jobs
> (both of which are limited to 1000).
>

./SUBNET
[+] Generating IP-addresses ... please wait
[+] 2072640 IP-addresses has been generated ...
[+] Generating proxy list ... please wait
WTF ...
Segmentation fault

The code (SUBNET):

#!/bin/zsh

zmodload -i zsh/terminfo
zmodload -i zsh/datetime
zmodload -i zsh/mathfunc
zmodload -i zsh/pcre
zmodload -i zsh/mapfile

emulate zsh

exec 2>/tmp/zsh$$trace
setopt xtrace

#HOST_MIN="10.100.12.1"
#HOST_MAX="10.100.12.14"

#HOST_MIN="10.100.12.1"
#HOST_MAX="10.100.15.254"

#HOST_MIN="10.96.0.1"
#HOST_MAX="10.111.255.254"

#HOST_MIN="183.190.0.1"
#HOST_MAX="183.191.255.254"

HOST_MIN="128.96.0.1"
HOST_MAX="128.127.255.254"

#HOST_MIN="128.96.0.1"
#HOST_MAX="128.111.255.254"

IFS="."

HOST_MIN_A=$(print ${${HOST_MIN[*]}[(w)1]})
HOST_MIN_B=$(print ${${HOST_MIN[*]}[(w)2]})
HOST_MIN_C=$(print ${${HOST_MIN[*]}[(w)3]})
HOST_MIN_D=$(print ${${HOST_MIN[*]}[(w)4]})

HOST_MAX_A=$(print ${${HOST_MAX[*]}[(w)1]})
HOST_MAX_B=$(print ${${HOST_MAX[*]}[(w)2]})
HOST_MAX_C=$(print ${${HOST_MAX[*]}[(w)3]})
HOST_MAX_D=$(print ${${HOST_MAX[*]}[(w)4]})

unset IFS

typeset -gA IPS
typeset -gA PARTS

PORTS="80 1080"

Proxy_List="$PWD/PROXIES.NIX"

[ -f "$Proxy_List" ] && { rm -f $Proxy_List }

echo "[+] Generating IP-addresses ... please wait"

# 0/16 - 0/23

if [ "$HOST_MIN_A" = "$HOST_MAX_A" ] && [ "$HOST_MIN_B" = "$HOST_MAX_B" ]
&& [ "$HOST_MIN_C" != "$HOST_MAX_C" ] ; then

START="$HOST_MIN_A.$HOST_MIN_B."

let "HOST_MAX_C++"

until [ "$HOST_MIN_C" -eq "$HOST_MAX_C" ] ; do

for i in {1..254} ; do

IP="$START$HOST_MIN_C.$i"
IPS[$IP]=$IP

done

let "HOST_MIN_C++"

done

# 0/24

elif [ "$HOST_MIN_A" = "$HOST_MAX_A" ] && [ "$HOST_MIN_B" = "$HOST_MAX_B"
] && [ "$HOST_MIN_C" = "$HOST_MAX_C" ] ; then

START="$HOST_MIN_A.$HOST_MIN_B.$HOST_MIN_C."

for i in {1..254} ; do

IP="$START$i"
IPS[$IP]=$IP

done

# 0/8 - 0/15

elif [ "$HOST_MIN_A" = "$HOST_MAX_A" ] && [ "$HOST_MIN_B" != "$HOST_MAX_B"
] ; then

START="$HOST_MIN_A."

let "HOST_MAX_B++"

until [ "$HOST_MIN_B" -eq "$HOST_MAX_B" ] ; do

for i in {1..255} ; do

PART="$START$HOST_MIN_B.$i."
PARTS[$PART]=$PART

[ $i = "255" ] && { let "HOST_MIN_B++" ; break }
done

done

foreach PART ($PARTS)

for x in {1..254} ; do

IP="$PART$x"
IPS[$IP]=$IP
done

end

unset PARTS

else

echo "Error: This CIDR or IP & Subnet Mask is not currently supported." ;
exit
fi

NoIPs="${#IPS[*]}"
NoPorts=$(print ${(w)#PORTS})

Total=$[NoIPs * $NoPorts]

echo "[+] $NoIPs IP-addresses has been generated ..."
echo "[+] Generating proxy list ... please wait"

for PORT in `echo $PORTS` ; do

PROXIES=()
PROXIES+=(${^IPS}:$PORT)

echo "WTF ..."

print -l ${(n)PROXIES} >> $Proxy_List

unset PROXIES

done

echo "[+] $Total proxies has been generated. Proxy list $Proxy_List is now
ready for scanning."

---

Line 143: print -l ${(n)PROXIES} >> $Proxy_List causes segfault. I can't
see where the problem is, if you try IP range up to one million, it will
work good.

PS. Beware of about 1,45GB RAM usage while using that script.

http://myproxylists.com/online-subnet-calculator

Enter the following CIDR: 128.100.12.0/11 to get a 2097150 hosts
(elements) to 'SUBNET' script array. This info is already set into
'SUBNET' but just to get a picture what im trying to do.

As you might already figured out, PHP code does subnet calculation and my
ZSH script 'SUBNET' generates IP-ranges accordingly. Quite cool is not
after segfault bug has been fixed.






Messages sorted by: Reverse Date, Date, Thread, Author