6
6
6stprod2016-08-26 07:18:34
C++ / C#
6stprod, 2016-08-26 07:18:34

C# how to catch an outgoing connection on a separate IP or domain?

I am making a console application that should check the connection to a specific IP and notify (for example: You connected to 127.0.0.1). How to implement it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rou1997, 2016-08-26
@Rou1997

This is a sniffer, not easy to implement, try the WinPCap driver (used in Wireshark), or the Fiddler library, it acts like a proxy and is easier to deal with, but it is only for HTTP and HTTPS.

A
alex_ak1, 2016-08-26
@alex_ak1

winpcap and some pcap dot net , watch all traffic and filter connections.

6
6stprod, 2016-08-26
@6stprod

static void ListAvailableTCPPort(ref ArrayList usedPort)
        {
            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
            IEnumerator myEnum = tcpConnInfoArray.GetEnumerator();

            while (myEnum.MoveNext())
            {
                TcpConnectionInformation TCPInfo = (TcpConnectionInformation)myEnum.Current;
                Console.WriteLine("Port {0} {1} {2} ", TCPInfo.LocalEndPoint, TCPInfo.RemoteEndPoint, TCPInfo.State);
                usedPort.Add(TCPInfo.LocalEndPoint.Port);
            }
        }

        public static void Main()
        {
            ArrayList usedPorts = new ArrayList();
            ListAvailableTCPPort(ref usedPorts);
            Console.ReadKey();
        }
How can I filter the required connection from this list?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question