Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

How to send Broadcast message

by ralijani (Acolyte)
on Jun 25, 2003 at 11:12 UTC ( #268810=perlquestion: print w/replies, xml ) Need Help??

ralijani has asked for the wisdom of the Perl Monks concerning the following question:

I want to send a broad cast message on tcp/ip protocol to a host or Net address that user can read it. I want to do it on linux machine with perl. is there any way to do it?

Replies are listed 'Best First'.
Re: How to send Broadcast message
by cbro (Pilgrim) on Jun 25, 2003 at 12:23 UTC
    Try perldoc IO::Socket. Here's a little example:
    use IO::Socket; $socket = IO::Socket::INET->new ( PeerAddr => '', PeerPort => #<open port e.g. 80>, Proto => "tcp", Type => SOCK_STREAM ) or die "Could Not open port"; print $socket "Server message\n"; close($socket);

    Now, how you interpret messages on the other side is up to you. You can write a server program that mirrors this example above, you can use something like tcpdump with the '-x' option for hexidecimal encoding and decode the message, or you may already have something.
      sory but i want to send message to all microsoft and linux client without any client application on my client
      use IO::Socket::Multicast; # create a new UDP socket ready to read datagrams on port 1100 my $s = IO::Socket::Multicast->new(LocalPort=>1100); # Add a multicast group $s->mcast_add(''); # Add a multicast group to eth0 device $s->mcast_add('','eth0'); # now receive some multicast data $s->recv($data,1024); # Drop a multicast group $s->mcast_drop(''); # Set outgoing interface to eth0 $s->mcast_if('eth0'); # Set time to live on outgoing multicast packets $s->mcast_ttl(10); # Turn off loopbacking $s->mcast_loopback(0); # Multicast a message to group $s->mcast_send('hello world!',''); $s->mcast_set(''); $s->mcast_send('hello again!');

      update (broquaint): added <code> tags

        A 'client' is a 'client application' - you can broadcast messages wherever you like, but unless something's listening and acting on those messages, they're not a lot of good. You can't just send a message to a machine and expect it to magically do something...what were you expecting, exactly? mcast_send(PopupWindow=>1,PlaySound=>"ding.wav")? Anything that causes the client to take action must aleady be running on the client machine.

        Two paragraphs down fom the IO::Socket::Multicast synopsis you've pasted in there, it explains how to write a multicast client that will listen to your multicast server. That should get you started, if this is what you need.

        Cheers, Ben.

Re: How to send Broadcast message
by fglock (Vicar) on Jun 25, 2003 at 14:27 UTC

    I can send a text message from a Windows machine to another Windows machine with this:

    perl -e " system 'net send fglock hello world ' "

    You can probably do this from Linux using one of the SMB tools. I'll make some tests.

    Update: smbclient -M COMPUTERNAME will do it. There must be a way to do broadcast, but I can't find it

      I think if you do
      net send hello
      it sends to all. I remember doing this in the dorm.. but can't really test that here at work..
      hi dear thanks for your reply. but when i run smb and run smbclient -M hostname i get : root@SEPEHR samba# smbclient -M dns added interface ip= bcast= nmask= Cannot resolve name dns#0x3 root@SEPEHR samba# i did not configure samba just i run it. what is my problem. i can ping : ping dns and it reply how could i solve my problem. Best Regurd

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://268810]
Approved by gellyfish
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2020-06-04 15:12 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (32 votes). Check out past polls.