rendered paste bodyusing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
namespace Portscanner
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtIP;
private System.Windows.Forms.NumericUpDown numStart;
private System.Windows.Forms.NumericUpDown numEnd;
private System.Windows.Forms.RichTextBox txtLog;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtIP = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.numStart = new System.Windows.Forms.NumericUpDown();
this.numEnd = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.txtLog = new System.Windows.Forms.RichTextBox();
((System.ComponentModel.ISupportInitialize)(this.numStart)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numEnd)).BeginInit();
this.SuspendLayout();
//
// txtIP
//
this.txtIP.Location = new System.Drawing.Point(72, 16);
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(136, 20);
this.txtIP.TabIndex = 0;
this.txtIP.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 24);
this.label1.TabIndex = 1;
this.label1.Text = "Ip nummer:";
//
// numStart
//
this.numStart.Location = new System.Drawing.Point(72, 64);
this.numStart.Name = "numStart";
this.numStart.Size = new System.Drawing.Size(48, 20);
this.numStart.TabIndex = 2;
//
// numEnd
//
this.numEnd.Location = new System.Drawing.Point(192, 64);
this.numEnd.Name = "numEnd";
this.numEnd.Size = new System.Drawing.Size(48, 20);
this.numEnd.TabIndex = 3;
//
// label2
//
this.label2.Location = new System.Drawing.Point(0, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 24);
this.label2.TabIndex = 4;
this.label2.Text = "Start port:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(128, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 24);
this.label3.TabIndex = 5;
this.label3.Text = "Slut port:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 32);
this.button1.TabIndex = 6;
this.button1.Text = "Starta";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtLog
//
this.txtLog.Location = new System.Drawing.Point(256, 8);
this.txtLog.Name = "txtLog";
this.txtLog.Size = new System.Drawing.Size(240, 224);
this.txtLog.TabIndex = 7;
this.txtLog.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 242);
this.Controls.Add(this.txtLog);
this.Controls.Add(this.button1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.numEnd);
this.Controls.Add(this.numStart);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtIP);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.numStart)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numEnd)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
// Store values from the NumericUpDown to variables
int StartPort = Convert.ToInt32(numStart.Value);
int EndPort = Convert.ToInt32(numEnd.Value);
// 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" + "\n");
}
catch
{
// An exception occured, thus the port is probably closed
txtLog.AppendText("Port " + CurrPort + " closed" + "\n");
}
}
// Set the cursor back to normal
Cursor.Current = Cursors.Arrow;
}
}
}