Ports

Hi guy’s i’m learning some stuff

i have a script here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Net.NetworkInformation;

public class NETWORK_CHECKER : MonoBehaviour
{
    int PORT;
    private static bool IsPortBeingUsed(int port)
    {
        return IPGlobalProperties.GetIPGlobalProperties().
                    GetActiveTcpConnections().
                        Any(
                                tcpConnectionInformation =>
                                tcpConnectionInformation.LocalEndPoint.Port == port
                           );
    }

    private void Update()
    {
        if (Input.GetKey(KeyCode.A))
        {
            var J = IsPortBeingUsed(PORT);
            Debug.Log(J + " " + PORT);
            PORT = PORT + 1;
          
        }
    }
}

I ran this baby and it returned true on port 135 and 445.

Without internet connection;

Any idea what this might mean? Why even?

Port 135 is used by Microsoft RPC (remote procedure call)
Port 445 is used for SMB (file and printer sharing)

Both of these ports are commonly used by Windows services and processes.

It doesn’t matter if your computer is connected to a network or not because your local computer can have running programs that are either clients or services or both, and they can communicate with each other over the local loopback connection.

3 Likes

Thank you i found out about 135 but 445 thank you

Hey

    private void Display()
    {
        IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();

  
        TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();

        foreach (TcpConnectionInformation info in tcpConnections)
        {
            Debug.Log("Local: {0}:{1}\nRemote: {2}:{3}\nState: {4}\n" + " " + info.LocalEndPoint.Address + " " + " " + info.LocalEndPoint.Port
                + " " + info.RemoteEndPoint.Address + " " + info.RemoteEndPoint.Port + " " + info.State);
        }
    }

I ran this baby,

and I found this
34.149.112.94 443 Established

connection established to me IP address owned by Google LLC located USA, no chrome, no youtube, any idea’s?

i’ve also found a

20.90.152.133 is located in GB IP Address at latitude 51.5164 and longitude -0.093 city of london.
Not me.

I know its craziness

I also got me a 76.223.31.44 Amazon owned Seattle Washington on port 80

I’ve got a WarSaw Poland 93.184.221.240 port 80. Seatle and Poland sharing.

Am I out of my mind? Should I be concerned?

The resource monitor can help you identify which programs have open connections.

1 Like

that it can

That it can.

I wish I knew this stuff years ago so I could have switched forced windows updates off -_-

I don’t know if you can stop updates by stopping the networking connection like that but you can set up a group policy for your computer that stops automatic updates. At least you can with Windows Professional. I don’t know about Home.

https://en.wikipedia.org/wiki/Group_Policy

1 Like

I think I could https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient.close?view=net-8.0

Windows updates not important these days I was just saying that’s the route I would take.

private void CLOSE_TCP_PORT(int NUMBER)
    {
        IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
        TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
        for (int i = 0; i < tcpConnections.Length; i++)
        {
            if (tcpConnections[i].LocalEndPoint.Port.Equals(NUMBER))
            {
                // Close it here somehow :) i'll figure it
                Debug.Log(tcpConnections[i].LocalEndPoint.Address + " " + " " + tcpConnections[i].LocalEndPoint.Port
               + " " + tcpConnections[i].RemoteEndPoint.Address + " " + tcpConnections[i].RemoteEndPoint.Port + " " + tcpConnections[i].State);
            }
        }
    }

I don’t close it yet, but I believe something like this match local-end-point close the local end point.

 private void CLOSE_TCP_PORT(string IP_TO_DROP)
    {
        IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
        TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
        for (int i = 0; i < tcpConnections.Length; i++)
        {
            if (tcpConnections[i].RemoteEndPoint.Address.ToString().Contains(IP_TO_DROP))
            {
                var endPoint = new IPEndPoint(tcpConnections[i].RemoteEndPoint.Address, tcpConnections[i].RemoteEndPoint.Port);
                using var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                /// Chaotic Learning Experience
                socket.Close();
                //socket.Bind(endPoint);
                /*
                try
                {
                    socket.Listen(10);
                   
                    Debug.Log("LISTENING"); 
                }
                catch (SocketException)
                {
                    socket.Dispose();
                }
                */
                socket.Dispose();
                ///  Probably does nothing
                /// Listen maybe if we cant close a connection i can flood it and corrupt the packets on exit. 
                /// Yeah now we enter the realm of crazy, why? IT is a Hunt for the hidden Enemy.
                /// This is the new game. Find the Enemy. 
                /// Im not sure why it is so chaotic to learn this, but i imagine it is chaotic to learn because the fundamental system is insecure.
            }
        }
    }

This as far as I go, Looks like it may not be possible to block it or cancel it without identifying and destroying the process which of course can be hidden. Funnily the IP’s from last night are gone. I only have seemingly legit ones on there. So, not to worry about. It is still useful to analyze my phone for hacking. Since I deal with various notorious phone hacking and broadcast agencies who control various narrative. As you can imagine we are quite intelligent of peoples, but the gap between the intelligences of normal people, means that I can make people believe just about anything. And often they do, and so they get paranoid so I assume would be inclined to pursue the truth behind the veil. But this is a total ramble guys.

I’m gonna get back to game dev. Mul this over for a month or so.

        IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
        TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
        bool FOUND_UNUSED_PORT = true;
        for (int i = 0; i < 60000; i++)
        {
           FOUND_UNUSED_PORT = true;
           for (int x = 0; x < tcpConnections.Length; x++)
            {
                if (tcpConnections[x].LocalEndPoint.Port == i)
                {
                    FOUND_UNUSED_PORT = false;
                    USED_PORTS.Add(i);
                    break;
                }
            }
           if (i != 445 && i != 135)
            {
                var endPoint = new IPEndPoint(IPAddress.Loopback, i);
                using var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                socket.Bind(endPoint);
                try
                {
                    socket.Listen(10);
                    Debug.Log("LISTENING on port " + i);
                }
                catch (SocketException)
                {
                    socket.Dispose();
                }
                socket.Close();
                socket.Dispose();
              
            }
        }

this one clears all my ports; which I was using 35 ports, and this one goes through them, ignores ones with permission, and apparently after that they are no longer using. From 35 down to 11.

some stuff gets flagged up so I write code to get past it

SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted.
so this tells me at port 5037 I have something on my machine that has a socket set up here.
Socket Access Permissions need to be checked to see if the port is protected.

Originally I excluded all sockets that were occupied using the found unused port bool. But I wanted memory wipe them all. Except the microsoft one. I am left with a small list of IP addresses using the sockets. 3 of them ipv6 and the rest normal IP.

You keep posting stuff here and bumping this thread. However this seems quite unrelated to Unity game development. If you want to know what ports are currenty open / listening or connected you can simply run netstat with admin privileges. Press WinKey+R, enter “cmd”, hold Shift+Ctrl and press enter. This will start cmd with admin privileges.
In cmd you can simply enter:

netstat -a -n -o -b

“a” shows all connections, “n” makes sure addresses and ports are shown numerical (if not it tries to do a reverse DNS lookup which is slow, really slow), “o” shows the process ID that holds that port and “b” shows the application name of each port / connection. The application name will be shown after the connection in a new line. Most of that stuff can be seen in the resource monitor as @eisenpony already pointed out.

Note that sockets are also used for interprocess communication, not just for network or internet traffic. Also note that when you have a listening socket that is bound to the local address “0.0.0.0” it means it can accept connections from anywhere as long as they can actually reach your machine. When you see a listening socket that is bound to 127.0.0.1 only other applications on the same machine can actually connect to this socket.

I have no idea what you actually want to achieve here. You try to temporarily open a socket on (almost) every port which is just crazy stupid. What is your actual goal? On my machine I have tons of listening sockets because I have a filezilla FTP server, a mysql server and a lot of other stuff running on my machine. How is any of that related to Unity? Be warned that when you plan to include such sniffing code in your game, chances are high that antivirus software may detect a (false?!) positive.