Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using System.Threading;
- using System.IO;
- using System.Security.Cryptography;
- using System.Collections;
- using System.Net;
- using System.Net.Sockets;
- namespace TimeAnalyze
- {
- class Program
- {
- #region Time
- //*
- static Stopwatch sw = new Stopwatch();
- static void Start()
- {
- sw.Reset();
- sw.Start();
- }
- static void Time()
- {
- Console.Error.WriteLine(sw.Elapsed);
- }
- static void Time(string text)
- {
- Console.Error.WriteLine(text + ": " + sw.Elapsed);
- }
- static void Stop()
- {
- sw.Stop();
- Time();
- }
- static void Stop(string text)
- {
- sw.Stop();
- Time(text);
- }
- //*/
- #endregion
- static object obj = new object();
- static object output = new object();
- static string host = "172.20.0.";
- static int i = 0;
- static void ThreadMethod()
- {
- int h;
- lock(obj)
- {
- h = i++;
- }
- if (h >= 65536) return;
- Socket skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- bool res = false;
- string host = string.Format("192.168.{1}.{0}", h & 0xFF, (h >> 2) & 0xFF);
- try
- {
- skt.Connect(host, 80);
- if (skt.Connected) res = true;
- }
- catch
- {
- }
- lock (output)
- {
- if (res)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- File.AppendAllText("output.txt", host + "\r\n");
- Console.Title = "Complete";
- }
- Console.WriteLine("{0} {1}", host, res);
- Console.ResetColor();
- }
- }
- static void Main(string[] args)
- {
- Thread[] threads = new Thread[1000];
- for(int i = 0; i < threads.Length; i++)
- {
- threads[i] = new Thread(() =>
- {
- while (i < 65536) ThreadMethod();
- });
- threads[i].Start();
- }
- while (true) Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement