Way too much happened for me to create a commit message

This commit is contained in:
2025-02-07 18:44:22 +01:00
parent 680b295f9e
commit 83897c72cf
17 changed files with 233 additions and 91 deletions
+8 -5
View File
@@ -1,20 +1,23 @@
using System.Net;
using System.Net.Sockets;
using Models.Model.Backend;
namespace Backend.Helper;
public static class TcpClientHelper
{
public static (int, int) CheckPort(string ip, params int[] ports)
public static (int, int) CheckPort(Ip ip, params int[] ports)
{
// This would be way cleaner if the TcpClient didn't throw an exception if the destination couldn't be reached,
// and it would just return a result.error, for example.
for (int i = 0; i < ports.Length; i++) {
using Socket socket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.SendTimeout = 250;
try
{
using TcpClient client = new();
client.Connect(ip, ports[i]);
// If the connection is successful, update the result array with the port number
socket.Connect(ip.ToString(), ports[i]);
socket.Close();
// If the connection is not successful, update the ports array with 0.
}
catch
{