Beispiel #1
0
        /**
        Gets active TCP connections. Recursive function because properties.GetActiveTcpConnections may throw an
        exception sometimes...

        @return The active TCP connections.
        **/
        public static TcpConnectionInformation[] GetActiveTcpConnections(IPGlobalProperties properties, int tries)
        {
            while(tries > 0) {
                try {
                    return properties.GetActiveTcpConnections();
                } catch(NetworkInformationException) {
                    return GetActiveTcpConnections(properties, tries - 1);
                }
            }

            return null;
        }
Beispiel #2
0
        // Incoming data from the client.
        //public static string data = null;
        public Serveur()
        {
            // Establish the local endpoint for the socket.
            // Dns.GetHostName returns the name of the
            // host running the application.
            ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress[] tabIpAdress = ipHostInfo.AddressList;
            ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());

            ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            tcpConnInfoListe = ipGlobalProperties.GetActiveTcpConnections().ToList();

            foreach (IPAddress adress in tabIpAdress)//TODO: résoudre pb virtual box
                if (adress.AddressFamily == AddressFamily.InterNetwork)
                    ipAddress = adress;
        }
Beispiel #3
0
        private bool isPortOpen(int numPort)
        {
            ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            tcpConnInfoListe = ipGlobalProperties.GetActiveTcpConnections().ToList();

            return tcpConnInfoListe.Exists(tcp => tcp.LocalEndPoint.Port == numPort);
        }
        private string GetTcpStatistics(
            NetworkInterfaceComponent version,
            IPGlobalProperties properties)
        {
            TcpStatistics tcpStat = null;

            StringBuilder tcpStatBuilder = new StringBuilder();

            try
            {
                switch (version)
                {
                    case NetworkInterfaceComponent.IPv4:
                        tcpStat = properties.GetTcpIPv4Statistics();
                        tcpStatBuilder.Append("TCP/IPv4 Statistics\n");
                        break;
                    case NetworkInterfaceComponent.IPv6:
                        tcpStat = properties.GetTcpIPv6Statistics();
                        tcpStatBuilder.Append("TCP/IPv6 Statistics\n");
                        break;
                    default:
                        throw new ArgumentException("No such IP version");

                }
            }
            catch (NetworkInformationException)
            {
                return String.Empty;
            }

            tcpStatBuilder.Append("=================================================\n");

            tcpStatBuilder.AppendFormat(" Minimum Transmission Timeout .. : {0}\n",
                tcpStat.MinimumTransmissionTimeout);
            tcpStatBuilder.AppendFormat(" Maximum Transmission Timeout .. : {0}\n",
                tcpStat.MaximumTransmissionTimeout);
            tcpStatBuilder.AppendFormat(" Maximum Connections ........... : {0}\n",
                tcpStat.MaximumConnections);

            tcpStatBuilder.AppendFormat(" Connection Data:\n");
            tcpStatBuilder.AppendFormat("  Current ...................... : {0}\n",
            tcpStat.CurrentConnections);
            tcpStatBuilder.AppendFormat("  Cumulative ................... : {0}\n",
                tcpStat.CumulativeConnections);
            tcpStatBuilder.AppendFormat("  Initiated .................... : {0}\n",
                tcpStat.ConnectionsInitiated);
            tcpStatBuilder.AppendFormat("  Accepted ..................... : {0}\n",
                tcpStat.ConnectionsAccepted);
            tcpStatBuilder.AppendFormat("  Failed Attempts .............. : {0}\n",
                tcpStat.FailedConnectionAttempts);
            tcpStatBuilder.AppendFormat("  Reset ........................ : {0}\n",
                tcpStat.ResetConnections);
            tcpStatBuilder.AppendFormat("  Errors ....................... : {0}\n",
                tcpStat.ErrorsReceived);

            tcpStatBuilder.AppendFormat(" Segment Data:\n");
            tcpStatBuilder.AppendFormat("  Received ..................... : {0}\n",
                tcpStat.SegmentsReceived);
            tcpStatBuilder.AppendFormat("  Sent ......................... : {0}\n",
                tcpStat.SegmentsSent);
            tcpStatBuilder.AppendFormat("  Retransmitted ................ : {0}\n",
                tcpStat.SegmentsResent);
            tcpStatBuilder.AppendFormat("  Resent with reset ............ : {0}\n",
                tcpStat.ResetsSent);

            TcpConnectionInformation[] connectionsInfo = properties.GetActiveTcpConnections();

            tcpStatBuilder.AppendFormat(" Active Connections ............ : {0}\n",
                connectionsInfo.Length);

            if (connectionsInfo.Length > 0)
            {
                tcpStatBuilder.Append("  Local Address   Port   Remote Address  Port\n");
            }

            foreach (TcpConnectionInformation connectionInfo in connectionsInfo)
            {
                tcpStatBuilder.AppendFormat("  {0, -15}:{1}   {2, -15}:{3}\n",
                    connectionInfo.LocalEndPoint.Address,
                    connectionInfo.LocalEndPoint.Port,
                    connectionInfo.RemoteEndPoint.Address,
                    connectionInfo.RemoteEndPoint.Port);
            }

            IPEndPoint[] endPoints = properties.GetActiveTcpListeners();

            tcpStatBuilder.AppendFormat(" TCP Listeners ................. : {0}\n",
                endPoints.Length);

            if (endPoints.Length > 0)
            {
                tcpStatBuilder.Append("  Local Address   Port\n");
            }

            foreach (IPEndPoint endPoint in endPoints)
            {
                tcpStatBuilder.AppendFormat("  {0, -15}:{1}\n",
                    endPoint.Address, endPoint.Port);
            }

            return tcpStatBuilder.ToString();
        }
Beispiel #5
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            System.Net.NetworkInformation.IPGlobalProperties ipgp = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
            System.Net.NetworkInformation.TcpStatistics      ts   = ipgp.GetTcpIPv4Statistics();
            System.Net.NetworkInformation.UdpStatistics      us   = ipgp.GetUdpIPv4Statistics();
            ArrayList al   = new ArrayList();
            ArrayList alus = new ArrayList();

            al.Add(ts);
            alus.Add(us);
            if (dataGridView6.DataSource == null || (dataGridView6.DataSource != null && !((ArrayList)dataGridView6.DataSource).Equals(alus)))
            {
                try
                {
                    dataGridView6.DataSource = alus;
                }
                catch { }
            }

            if (dataGridView5.DataSource == null || (dataGridView5.DataSource != null && !((ArrayList)dataGridView5.DataSource).Equals(al)))
            {
                try
                {
                    dataGridView5.DataSource = al;
                }
                catch { }
            }

            System.Net.IPEndPoint[] udplist = ipgp.GetActiveUdpListeners();
            if (dataGridView4.DataSource == null || (dataGridView4.DataSource != null && !((System.Net.IPEndPoint[])dataGridView4.DataSource).Equals(udplist)))
            {
                try
                {
                    dataGridView4.DataSource = udplist;
                }
                catch { }
            }
            System.Net.IPEndPoint[] tcplist = ipgp.GetActiveTcpListeners();
            if (dataGridView3.DataSource == null || (dataGridView3.DataSource != null && !((System.Net.IPEndPoint[])dataGridView3.DataSource).Equals(tcplist)))
            {
                try
                {
                    dataGridView3.DataSource = tcplist;
                }
                catch { }
            }
            System.Net.NetworkInformation.TcpConnectionInformation[] tci = ipgp.GetActiveTcpConnections();

            if (dataGridView2.DataSource == null || (dataGridView2.DataSource != null && !((System.Net.NetworkInformation.TcpConnectionInformation[])dataGridView2.DataSource).Equals(tci)))
            {
                try
                {
                    dataGridView2.DataSource = tci;
                }
                catch { }
            }


            FileInfo nfi = new FileInfo(strPath);

            if (nfi.LastWriteTime > fi.LastWriteTime)
            {
                RefreshLog();
            }
        }
Beispiel #6
0
        protected bool IsConnect(int PortNO)
        {
            bool Connect = false;
            properties = IPGlobalProperties.GetIPGlobalProperties();
            connections = properties.GetActiveTcpConnections();

            if (connections.Length > 0)
            {
                foreach (TcpConnectionInformation TCPinfor in connections)
                {

                    if (TCPinfor.State == TcpState.Established & TCPinfor.RemoteEndPoint.Port == PortNO)
                    {
                        Connect = true;
                    }
                }
            }

            return Connect;
        }
 private string GetLocalEndPoint(System.Net.Sockets.Socket s)
 {
     System.Net.NetworkInformation.IPGlobalProperties         iPGlobalProperties   = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
     System.Net.NetworkInformation.TcpConnectionInformation[] activeTcpConnections = iPGlobalProperties.GetActiveTcpConnections();
     System.Net.IPEndPoint iPEndPoint = (System.Net.IPEndPoint)s.RemoteEndPoint;
     System.Net.NetworkInformation.TcpConnectionInformation[] array = activeTcpConnections;
     for (int i = 0; i < array.Length; i++)
     {
         System.Net.NetworkInformation.TcpConnectionInformation tcpConnectionInformation = array[i];
         if (iPEndPoint.ToString() == tcpConnectionInformation.RemoteEndPoint.ToString())
         {
             return(new System.Net.IPEndPoint(tcpConnectionInformation.LocalEndPoint.Address, ((System.Net.IPEndPoint)s.LocalEndPoint).Port).ToString());
         }
     }
     return("127.0.0.1:0");
 }