Example #1
0
        public static void ScanIP(Action <ScanResult> callback, Action <int, int, int> progress, CancellationToken ct, int port, IPAddress paramIP = null)
        {
            int count = 0;

            if (callback == null)
            {
                throw new ArgumentNullException(string.Format("Callback needed"));
            }
            if (progress == null)
            {
                throw new ArgumentNullException(string.Format("Progress needed"));
            }

            var localIP = paramIP ?? IPAddressHelper.GetLocalIP();

            if (localIP == null)
            {
                throw new Exception(string.Format("Can't find network adapter for IP {0}", paramIP));
            }
            var localMask = localIP.GetSubnetMask();

            if (localMask == null)
            {
                throw new Exception(string.Format("Can't find subnet mask for IP {0}", localIP));
            }

            IPSegment        segment = new IPSegment(localIP, localMask);
            IPSegmentScanner scanner = new IPSegmentScanner(segment, callback, progress, port, ct);

            scanner.FastScan();
            //scanner.FullScan();
        }
 private void ScanAsync()
 {
     C = new CancellationTokenSource();
     IPAddressHelper.ScanIP(ScanOutput, ScanProgress, C.Token, (int)UdPort.Value);             //bloccante
     OnScanEnd();
 }