コード例 #1
0
ファイル: DlgNetworkScanner.cs プロジェクト: sschoen/WOL2
        void BtnScanClick(object sender, EventArgs e)
        {
            try
            {
                String sNet = cboNetwork.Text;
                int    iPos = sNet.IndexOf("-");
                if (iPos > 0)
                {
                    sNet = sNet.Substring(0, iPos).Trim();
                }
                else
                {
                    return;
                }

                String sBc   = cboNetwork.Text;
                int    iPos2 = sBc.IndexOf("/", ++iPos);
                if (iPos2 > 0)
                {
                    sBc = sBc.Substring(iPos, iPos2 - iPos).Trim();
                }
                else
                {
                    return;
                }

                String sNm = cboNetwork.Text;
                sNm = sNm.Substring(++iPos2, sNm.Length - iPos2).Trim();


                IPAddress from = IPAddress.Parse(sNet);
                IPAddress to   = IPAddress.Parse(sBc);
                IPAddress nm   = IPAddress.Parse(sNm);

                btnScan.Enabled = false;

                m_NetworkScanner = new WOLNetworkScanner(new AsyncCallback(NetworkScanFinished), new AsyncCallback(NetworkScanStateCallback));
                m_NetworkScanner.SetPingTimeout(m_iPingTimeout);
                m_NetworkScanner.SetUnresolvedMacOk(m_bUnresolvedMacOk);
                m_NetworkScanner.SetUnsesolvedNameOk(m_bUnresolvedNameOk);
                m_NetworkScanner.ScanIPv4Range(from, to, nm);
            }
            catch (Exception ex)
            {
                MOE.Logger.DoLog("DlgNetworkScanner: " + ex.ToString(), MOE.Logger.LogLevel.lvlError);
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Minguh/WOL2
 private void ScanLocalSubnetsForNewHosts()
 {
     try
     {
         m_NetworkScanner = new WOLNetworkScanner(new AsyncCallback(NetworkScanFinished), new AsyncCallback(NetworkScanStateCallback));
         m_NetworkScanner.SetPingTimeout(m_iPingTimeout);
         m_NetworkScanner.SetUnresolvedMacOk(m_bUnresolvedMacOk);
         m_NetworkScanner.SetUnsesolvedNameOk(m_bUnresolvedNameOk);
         m_NetworkScanner.ScanSubnets();
         lblStatus.Text = MOE.Utility.GetStringFromRes("strNetworkScanStarted");
     }
     catch (Exception ex)
     {
         MOE.Logger.DoLog("ScanLocalSubnetsForNewHosts(): " + ex.ToString(), Logger.LogLevel.lvlError);
     }
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Minguh/WOL2
        /// <summary>
        /// Callback for the networkscanner to signal the end
        /// of the scan process.
        /// </summary>
        /// <param name="result">The result is a new host list.</param>
        public void NetworkScanFinished( IAsyncResult result )
        {
            // Check if we are running in the worker thread
            // If yes, we cannot access the list view.
            if( this.InvokeRequired )
            {
                // We are, so marshall this call
                Delegate myDelegate = new UpdateHostlist( NetworkScanFinished );
                this.Invoke( myDelegate,
                             result );
            }
            else
            {
                int iCount = 0;

                if (m_NetworkScanner == null)
                    return;

                Monitor.Enter( m_LockHosts );

                bool bChanged = false;

                foreach( WOL2Host h in m_NetworkScanner.Hosts )
                {
                    // Check if this host already exists

                    WOL2Host foundHost = null;
                    if (!m_Hosts.Exists(delegate(WOL2Host theHost) { foundHost = theHost;  return h.Equals(theHost); }))
                    {
                        if( h != null )
                        {
                            m_Hosts.Add( h );
                            bChanged = true;
                            iCount++;
                        }
                    }
                    else
                    {
                        if (foundHost != null)
                        {
                            MOE.Logger.DoLog("NetworkScanFinished: Updating host " + foundHost + "...", MOE.Logger.LogLevel.lvlInfo);

                            // If so, update it.
                            foundHost.SetIpAddress(h.GetIpAddress());
                            foundHost.SetIpV6Address(h.GetIpV6Address());
                            foundHost.SetSubnetMask(h.GetSubnetMask());
                            foundHost.SetMacAddress(h.GetMacAddress());
                            foundHost.SetName(h.GetName());

                            MOE.Logger.DoLog("NetworkScanFinished: Updated host " + foundHost, MOE.Logger.LogLevel.lvlInfo);

                            bChanged = true;
                        }
                    }
                }

                Monitor.Exit( m_LockHosts );

                lblStatus.Text = String.Format( MOE.Utility.GetStringFromRes("strNetworkScanFinished"), iCount);
                m_NetworkScanner = null;

                RefreshHostList();

                if( bChanged )
                    // Mark the file as changed
                    ChangedHostsFile();
            }
        }
コード例 #4
0
ファイル: DlgNetworkScanner.cs プロジェクト: Minguh/WOL2
        void BtnScanClick(object sender, EventArgs e)
        {
            try
            {
                String sNet = cboNetwork.Text;
                int iPos = sNet.IndexOf( "-" );
                if( iPos > 0 )
                {
                    sNet = sNet.Substring( 0, iPos ).Trim();
                }
                else
                    return;

                String sBc = cboNetwork.Text;
                int iPos2 = sBc.IndexOf( "/", ++iPos );
                if( iPos2 > 0 )
                {
                    sBc = sBc.Substring( iPos, iPos2-iPos ).Trim();
                }
                else
                    return;

                String sNm = cboNetwork.Text;
                sNm = sNm.Substring( ++iPos2, sNm.Length - iPos2 ).Trim();

                IPAddress from = IPAddress.Parse( sNet );
                IPAddress to = IPAddress.Parse( sBc );
                IPAddress nm = IPAddress.Parse( sNm );

                btnScan.Enabled = false;

                m_NetworkScanner = new WOLNetworkScanner(  new AsyncCallback( NetworkScanFinished ), new AsyncCallback( NetworkScanStateCallback ) );
                m_NetworkScanner.SetPingTimeout( m_iPingTimeout );
                m_NetworkScanner.SetUnresolvedMacOk( m_bUnresolvedMacOk );
                m_NetworkScanner.SetUnsesolvedNameOk( m_bUnresolvedNameOk );
                m_NetworkScanner.ScanIPv4Range( from, to, nm);
            }
            catch( Exception ex )
            {
                MOE.Logger.DoLog( "DlgNetworkScanner: " + ex.ToString(), MOE.Logger.LogLevel.lvlError );
            }
        }