zsh-users
 help / color / mirror / code / Atom feed
From: nix@myproxylists.com
To: "Bart Schaefer" <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: How to add string to end of each array element without loops
Date: Sat, 26 Mar 2011 04:39:08 +0200	[thread overview]
Message-ID: <b3f5af84c21435d21fed3f7705180821.squirrel@gameframe.net> (raw)
In-Reply-To: <110325191023.ZM31052@torch.brasslantern.com>

> On Mar 26,  3:37am, nix@myproxylists.com 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.





  reply	other threads:[~2011-03-26  2:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-25 21:32 nix
2011-03-25 21:45 ` Mikael Magnusson
2011-03-25 21:47   ` nix
2011-03-25 22:03 ` Bart Schaefer
2011-03-26  1:37   ` nix
2011-03-26  2:10     ` Bart Schaefer
2011-03-26  2:39       ` nix [this message]
2011-03-26  7:14         ` Bart Schaefer
2011-03-26 14:04           ` nix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3f5af84c21435d21fed3f7705180821.squirrel@gameframe.net \
    --to=nix@myproxylists.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).