Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using System.Threading;
  8. using System.IO;
  9. using System.Security.Cryptography;
  10. using System.Collections;
  11. using System.Net;
  12. using System.Net.Sockets;
  13.  
  14. namespace TimeAnalyze
  15. {
  16.     class Program
  17.     {
  18.         #region Time
  19.         //*
  20.         static Stopwatch sw = new Stopwatch();
  21.         static void Start()
  22.         {
  23.             sw.Reset();
  24.             sw.Start();
  25.         }
  26.         static void Time()
  27.         {
  28.             Console.Error.WriteLine(sw.Elapsed);
  29.         }
  30.         static void Time(string text)
  31.         {
  32.             Console.Error.WriteLine(text + ": " + sw.Elapsed);
  33.         }
  34.         static void Stop()
  35.         {
  36.             sw.Stop();
  37.             Time();
  38.         }
  39.         static void Stop(string text)
  40.         {
  41.             sw.Stop();
  42.             Time(text);
  43.         }
  44.         //*/
  45.         #endregion
  46.         static object obj = new object();
  47.         static object output = new object();
  48.         static string host = "172.20.0.";
  49.         static int i = 0;
  50.         static void ThreadMethod()
  51.         {
  52.             int h;
  53.             lock(obj)
  54.             {
  55.                 h = i++;
  56.             }
  57.             if (h >= 65536) return;
  58.  
  59.             Socket skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  60.             bool res = false;
  61.             string host = string.Format("192.168.{1}.{0}", h & 0xFF, (h >> 2) & 0xFF);
  62.  
  63.             try
  64.             {
  65.                 skt.Connect(host, 80);
  66.                 if (skt.Connected) res = true;
  67.             }
  68.             catch
  69.             {
  70.  
  71.             }
  72.  
  73.             lock (output)
  74.             {
  75.                 if (res)
  76.                 {
  77.                     Console.ForegroundColor = ConsoleColor.Green;
  78.                     File.AppendAllText("output.txt", host + "\r\n");
  79.                     Console.Title = "Complete";
  80.                 }
  81.                 Console.WriteLine("{0} {1}", host, res);
  82.                 Console.ResetColor();
  83.             }
  84.         }
  85.  
  86.         static void Main(string[] args)
  87.         {
  88.             Thread[] threads = new Thread[1000];
  89.             for(int i = 0; i < threads.Length; i++)
  90.             {
  91.                 threads[i] = new Thread(() =>
  92.                     {
  93.                         while (i < 65536) ThreadMethod();
  94.                     });
  95.                 threads[i].Start();
  96.             }
  97.  
  98.             while (true) Console.ReadKey(true);
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement