thieumao

Check port

Sep 1st, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net.Sockets;
  10.  
  11. namespace KiemTraPort
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         /// <summary>
  21.         /// Kiem tra port nao mo tu 1 den 1024
  22.         /// </summary>
  23.         private void btCheck_Click(object sender, EventArgs e)
  24.         {
  25.             tbPort.Text = "Please wait...";
  26.             TcpClient client = new TcpClient();
  27.             int iPort;
  28.             String strListPost = "";
  29.             for (iPort = 1; iPort <= 1024; iPort++)
  30.             {
  31.                 client = new TcpClient();
  32.                 try
  33.                 {
  34.                     client.Connect(tbIP.Text, iPort);
  35.                     strListPost += iPort.ToString() + " ";
  36.                     //tbPort.Text = strListPost;
  37.                 }
  38.                 catch (Exception ex)
  39.                 {
  40.                     //MessageBox.Show(ex.Message);
  41.                 }
  42.             }
  43.             tbPort.Text = strListPost;
  44.             MessageBox.Show("Check finish!");
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment