Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I AM NOT RESPONSIBLE FOR ANYTHING YOU DO WITH THIS CODE!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.NetworkInformation;
- using System.Net;
- using System.Net.Sockets;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.IO;
- using System.Windows.Forms;
- namespace EffectivePortScan
- {
- class Program
- {
- public static List<int> port = new List<int>();
- public static string ip = "";
- public static int portRangeMin = 0;
- public static int portRangeMax = 0;
- static void Main(string[] args)
- {
- Console.Write("IP: ");
- ip = Console.ReadLine();
- Console.Write("Start from port: ");
- portRangeMin = (Convert.ToInt32(Console.ReadLine()) - 1);
- Console.Write("Continue until port: ");
- portRangeMax = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- for (int i = 0; i < portRangeMax - portRangeMin; i++)
- {
- port.Add(0);
- }
- for (int i = 0; i < portRangeMax - portRangeMin; i++)
- {
- Thread.Sleep(250);
- Task.Run(() => scan(ip + portRangeMin, i));
- }
- Console.WriteLine("Finished with scan, writing to file...");
- Thread.Sleep(2500);
- TextWriter outputStream = new StreamWriter("output.txt", true);
- for (int i = 0; i < port.Count; i++)
- {
- if (port[i] == 0)
- outputStream.WriteLine((portRangeMin + i) + " : is closed");
- else
- outputStream.WriteLine((portRangeMin + i) + " : is open");
- }
- outputStream.Close();
- Console.WriteLine("I'm done!");
- Console.ReadLine();
- }
- async static Task scan(string ip, int p)
- {
- try
- {
- TcpClient ports = new TcpClient();
- ports.SendTimeout = 100;
- ports.SendBufferSize = 100;
- ports.Connect(ip, Convert.ToInt32(p));
- Console.WriteLine(p + ": Open");
- port[p] = 1;
- }
- catch
- {
- Console.WriteLine(p + ": Closed");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement