Hi,
For a purpose of testing I need a function which could tell me whether
it is possible to bind sockets on privileged ports or not.
I wrote down this simple function. It seems reasonably working to me
but I'd like to hear your opinion first.

Thanks in advance.


import socket, errno

def bind_on_privileged_ports(port=21):
    """Return True if it is possible to bind sockets on privileged
    ports (< 1024)."""
    try:
        s = socket.socket()
        s.bind(("", port))
    except socket.error, err:
        if err[0] == errno.EACCES:
            return False
    s.close()
    return True


--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to