thieumao

Check Port giao dien Console

Sep 2nd, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Net.Sockets;
  7.  
  8. namespace TestDaLuong
  9. {
  10.     class Server
  11.     {
  12.         public string IP { get; set; }
  13.         public int Port { get; set; }
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main()
  19.         {
  20.             Console.Write("Nhap IP hoac website can kiem tra: ");
  21.             String strWeb = Console.ReadLine();
  22.             Thread[] arrTh = new Thread[640];
  23.             for (int i = 0; i < arrTh.Length; i++)
  24.             {
  25.                 arrTh[i] = new Thread(Print);
  26.             }
  27.             for (int i = 0; i < arrTh.Length; i++)
  28.             {
  29.                 arrTh[i].Start(new Server() { IP = strWeb, Port = i * 100 });
  30.             }
  31.             Console.ReadKey();
  32.         }
  33.  
  34.         static void Print(object obj)
  35.         {
  36.             Server st = (Server)obj;
  37.             TcpClient client;
  38.             for (int iPort = st.Port; iPort < st.Port + 100; iPort++)
  39.             {
  40.                 client = new TcpClient();
  41.                 try
  42.                 {
  43.                     client.Connect(st.IP, iPort);
  44.                     Console.Write(st.Port.ToString() + "\t");
  45.                 }
  46.                 catch (Exception exc)
  47.                 {
  48.                     //MessageBox.Show(ex.Message);
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment