python broadcast socket
Jp Calderone
exarkun at divmod.com
Wed Jun 29 18:21:37 EDT 2005
On Thu, 30 Jun 2005 00:13:45 +0200, Irmen de Jong <irmen.nospam at xs4all.nl> wrote:
>Grant Edwards wrote:
>
>> Under Linux, you need to be root to send a broadcase packet.
>
>I don't think this is true.
>
I think you're right. I believe you just need to set the broadcast SOL_SOCKET option.
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> s.sendto('asdljk', ('255.255.255.255', 12345))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
socket.error: (13, 'Permission denied')
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
>>> s.sendto('asdljk', ('255.255.255.255', 12345))
6
>>>
Yep, looks like it.
Jp
More information about the Python-list
mailing list