UPnP Checking and updates
This commit is contained in:
66
TestUPnP/Program.cs
Normal file
66
TestUPnP/Program.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using QemuVmManager.Core;
|
||||
using System.Threading;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("🔍 Testing UPnP Functionality on macOS");
|
||||
Console.WriteLine("=====================================");
|
||||
|
||||
var upnpManager = new UPnPManager();
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine("\n1. Testing UPnP Availability (with shorter timeout)...");
|
||||
Console.WriteLine(" This may take up to 30 seconds...");
|
||||
|
||||
// Create a cancellation token with a reasonable timeout
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
|
||||
|
||||
var isAvailable = await upnpManager.IsUPnPAvailableAsync();
|
||||
Console.WriteLine($"UPnP Available: {isAvailable}");
|
||||
|
||||
if (isAvailable)
|
||||
{
|
||||
Console.WriteLine("\n2. Getting External IP via UPnP...");
|
||||
var externalIp = await upnpManager.GetExternalIpAddressAsync();
|
||||
Console.WriteLine($"External IP: {externalIp}");
|
||||
|
||||
Console.WriteLine("\n3. Testing Port Mapping...");
|
||||
var portMappingResult = await upnpManager.AddPortMappingAsync(8080, 80, "Test Mapping");
|
||||
Console.WriteLine($"Port Mapping Result: {portMappingResult}");
|
||||
|
||||
if (portMappingResult)
|
||||
{
|
||||
Console.WriteLine("\n4. Getting Port Mappings...");
|
||||
var mappings = await upnpManager.GetPortMappingsAsync();
|
||||
Console.WriteLine($"Active Mappings: {mappings.Count}");
|
||||
foreach (var mapping in mappings)
|
||||
{
|
||||
Console.WriteLine($" {mapping.ExternalPort} -> {mapping.InternalIp}:{mapping.InternalPort} ({mapping.Description})");
|
||||
}
|
||||
|
||||
Console.WriteLine("\n5. Removing Test Port Mapping...");
|
||||
var removeResult = await upnpManager.RemovePortMappingAsync(8080);
|
||||
Console.WriteLine($"Remove Result: {removeResult}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("\n2. Running UPnP Diagnostics...");
|
||||
var diagnostics = await upnpManager.GetUPnPDiagnosticsAsync();
|
||||
Console.WriteLine(diagnostics);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"❌ Error during UPnP testing: {ex.Message}");
|
||||
Console.WriteLine($"Stack trace: {ex.StackTrace}");
|
||||
}
|
||||
|
||||
Console.WriteLine("\n✅ UPnP Test Complete!");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user