choosing random dynamic port number

Grant Edwards grante at visi.com
Fri Jan 4 16:40:03 CET 2008


On 2008-01-04, Giampaolo Rodola' <gnewsg at gmail.com> wrote:

>>     def GenerateDynamicPortNumber():
>>         return 0
>>
>> (to get the actual number, use getsockname() on the socket after you've
>> called "bind" on it)
>>
>> </F>
>
> By using 0 as port number value you let kernel choose a free
> unprivileged random port:

The port number chosen isn't random on many OSes.  If the OP
really wants a random port number, he'll have to generate it
himself.

-- 
Grant Edwards                   grante             Yow! Look!  A ladder!
                                  at               Maybe it leads to heaven,
                               visi.com            or a sandwich!



More information about the Python-list mailing list