برنامه نویسی

using System.Net.Sockets; using System.Net.Sockets;

for (int CurrPort = 1; CurrPort <= 25; CurrPort++)

{

TcpClient TcpScan = new TcpClient();

try

{

// Try to connect

TcpScan.Connect("192.168.0.1", CurrPort);

// If there's no exception, we can say the port is open

MessageBox.Show("Port " + CurrPort + " open");

}

catch

{

// An exception occured, thus the port is probably closed

MessageBox.Show("Port " + CurrPort + " closed");

}

}

************************

************************

// Store values from the NumericUpDown to variables

StartPort = Convert.ToInt32(numStart.Value);

EndPort = Convert.ToInt32(numEnd.Value);

// Reset the progress bar

prgScanning.Value = 0;

// Set the max value of the progress bar

prgScanning.Maximum = EndPort - StartPort + 1;

// Let the user know the application is busy

Cursor.Current = Cursors.WaitCursor;

// Loop through the ports between start port and end port

for (int CurrPort = StartPort; CurrPort <= EndPort; CurrPort++)

{

TcpClient TcpScan = new TcpClient();

try

{

// Try to connect

TcpScan.Connect(txtIP.Text, CurrPort);

// If there's no exception, we can say the port is open

txtLog.AppendText("Port " + CurrPort + " open");

}

catch

{

// An exception occured, thus the port is probably closed

txtLog.AppendText("Port " + CurrPort + " closed");

}

// Increase the progress on the progress bar

prgScanning.PerformStep();

}

// Set the cursor back to normal

Cursor.Current = Cursors.Arrow;

+ نوشته شده در  پنجشنبه پانزدهم اردیبهشت ۱۳۹۰ساعت 11:21  توسط ابراری |