Re: How to know when it's possible to bind a socket on an unprivileged port?

2008-12-11 Thread Giampaolo Rodola'
Another way (probably more reliable): def bind_on_privileged_ports(): """Return True if it is possible to bind sockets on privileged ports (< 1024).""" for port in range(1, 1024)[::-1]: print port try: s = socket.socket() s.bind((HOST, port))

Re: How to know when it's possible to bind a socket on an unprivileged port?

2008-12-11 Thread Giampaolo Rodola'
On 11 Dic, 19:09, "Giampaolo Rodola'" wrote: > 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.

How to know when it's possible to bind a socket on an unprivileged port?

2008-12-11 Thread Giampaolo Rodola'
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