Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52884 > unrolled thread

How to send broadcast IP address to network?

Started bylightaiyee@gmail.com
First post2013-08-23 05:32 -0700
Last post2013-08-24 13:33 +0200
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  How to send broadcast IP address to network? lightaiyee@gmail.com - 2013-08-23 05:32 -0700
    Re: How to send broadcast IP address to network? lightaiyee@gmail.com - 2013-08-23 05:36 -0700
      Re: How to send broadcast IP address to network? Neil Cerutti <neilc@norwich.edu> - 2013-08-23 13:05 +0000
    Re: How to send broadcast IP address to network? Chris Angelico <rosuav@gmail.com> - 2013-08-24 00:11 +1000
    Re: How to send broadcast IP address to network? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-08-24 13:33 +0200

#52884 — How to send broadcast IP address to network?

Fromlightaiyee@gmail.com
Date2013-08-23 05:32 -0700
SubjectHow to send broadcast IP address to network?
Message-ID<659fa544-4fd6-406c-ad44-aa155e2c0e40@googlegroups.com>
I want to send a broadcast packet to all the computers connected to my home router. 

The following 2 lines of code do not work;
host="192.168.0.102"
s.connect((host, port))

Can someone advise?

Thank you.

[toc] | [next] | [standalone]


#52885

Fromlightaiyee@gmail.com
Date2013-08-23 05:36 -0700
Message-ID<b0ac44b7-8680-4bf3-a381-b010ee254cdf@googlegroups.com>
In reply to#52884
Some typo mistake. 
Should be host="192.168.0.255", not "192.168.0.102"

On Friday, August 23, 2013 8:32:10 PM UTC+8, light...@gmail.com wrote:
> I want to send a broadcast packet to all the computers connected to my home router. 
> 
> 
> 
> The following 2 lines of code do not work;
> 
> host="192.168.0.102"
> 
> s.connect((host, port))
> 
> 
> 
> Can someone advise?
> 
> 
> 
> Thank you.

[toc] | [prev] | [next] | [standalone]


#52887

FromNeil Cerutti <neilc@norwich.edu>
Date2013-08-23 13:05 +0000
Message-ID<b7p51fFhkssU2@mid.individual.net>
In reply to#52885
On 2013-08-23, lightaiyee@gmail.com <lightaiyee@gmail.com> wrote:
>> The following 2 lines of code do not work;
>> 
>> host="192.168.0.255"
>> host="192.168.0.102"
>> s.connect((host, port))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 's' is not defined

I bet that's not the same traceback you get. Furthermore, port
isn't defined either.

-- 
Neil Cerutti

[toc] | [prev] | [next] | [standalone]


#52894

FromChris Angelico <rosuav@gmail.com>
Date2013-08-24 00:11 +1000
Message-ID<mailman.165.1377267420.19984.python-list@python.org>
In reply to#52884
On Fri, Aug 23, 2013 at 10:32 PM,  <lightaiyee@gmail.com> wrote:
> I want to send a broadcast packet to all the computers connected to my home router.
>
> The following 2 lines of code do not work;
> host="192.168.0.102"
> s.connect((host, port))
>
> Can someone advise?

You can't establish a TCP socket with a broadcast address. That just
doesn't work. Can you please show a whole lot more context so we can
see what's happening here? Thanks!

ChrisA

[toc] | [prev] | [next] | [standalone]


#52937

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2013-08-24 13:33 +0200
Message-ID<521899fb$0$16011$e4fe514c@news.xs4all.nl>
In reply to#52884
On 23-8-2013 14:32, lightaiyee@gmail.com wrote:
> I want to send a broadcast packet to all the computers connected to my home router. 
> 
> The following 2 lines of code do not work;
> host="192.168.0.102"
> s.connect((host, port))
> 
> Can someone advise?
> 
> Thank you.
> 

Use UDP (datagram) sockets. Use sendto() and not connect(), because UDP is
connectionless. This should work:

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(b"thedata", 0, ("<broadcast>", 9999))    # 9999 = port
sock.close()


Irmen

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web