Created
September 26, 2019 02:09
-
-
Save mhagrelius/e7bbf2fbd14dd977c98b807984d78236 to your computer and use it in GitHub Desktop.
Stop Sonos Wifi Across Network
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
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