Skip to content

Instantly share code, notes, and snippets.

@creaktive
Last active May 24, 2018 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creaktive/0da98e7777501004907095961389efa2 to your computer and use it in GitHub Desktop.
Save creaktive/0da98e7777501004907095961389efa2 to your computer and use it in GitHub Desktop.
Reboot all the Sonos speakers in the LAN
#!/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