Last active
May 24, 2018 11:11
-
-
Save creaktive/0da98e7777501004907095961389efa2 to your computer and use it in GitHub Desktop.
Reboot all the Sonos speakers in the LAN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Net::UPnP::ControlPoint; | |
use WWW::Mechanize; | |
sub sonos_discover { | |
my @hosts; | |
my $cp = Net::UPnP::ControlPoint->new(); | |
for my $device ($cp->search(st => 'urn:schemas-upnp-org:device:ZonePlayer:1', mx => 1)) { | |
my ($ip, $model) = split(' - ', $device->getfriendlyname, 2); | |
push @hosts, $ip; | |
} | |
return @hosts; | |
} | |
sub sonos_reboot { | |
my ($host) = @_; | |
my $mech = WWW::Mechanize->new(); | |
$mech->get("http://$host:1400/reboot"); | |
$mech->submit_form(form_number => 1); | |
return; | |
} | |
sonos_reboot($_) for sonos_discover(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment