Skip to content

Instantly share code, notes, and snippets.

@mhagrelius
Created September 26, 2019 02:09
Show Gist options
  • Save mhagrelius/e7bbf2fbd14dd977c98b807984d78236 to your computer and use it in GitHub Desktop.
Save mhagrelius/e7bbf2fbd14dd977c98b807984d78236 to your computer and use it in GitHub Desktop.
Stop Sonos Wifi Across Network
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace SonosStopper
{
class Program
{
static async Task Main(string[] args)
{
var baseUrl = args[0].Trim();
Console.WriteLine($"Using the {baseUrl.Trim()}.{0} network.");
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromSeconds(15);
var results = Enumerable.Range(0, 255).AsParallel().Select(async entry =>
{
try
{
var url = $"http://{baseUrl}.{entry}";
var uri1 = new Uri($"{url}:1400/wifictrl?wifi=off)");
var uri2 = new Uri($"{url}:1400/wifictrl?wifi=persist-off");
using (var request = await client.GetAsync(uri1))
{
if (request.IsSuccessStatusCode)
{
Console.WriteLine($"Successfully sent wifi off signal to {url}");
}
else
{
Console.WriteLine($"Unable to turn off wifi at {url}");
}
}
using (var request = await client.GetAsync(uri2))
{
if (request.IsSuccessStatusCode)
{
Console.WriteLine($"Successfully sent permenant wifi off signal to {url}");
}
else
{
Console.WriteLine($"Unable to turn off wifi permanently at {url}");
}
}
}
catch(Exception ex)
{
Console.WriteLine($"Error encountered while trying to communicate with {baseUrl}.{entry}.");
}
}).ToList();
await Task.WhenAll(results);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment