Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Port Scanner based on C#

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to implement port scanner based on C #. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Create a new project and set up the interface

Create a new project:

Select the Windows forms project application (.Net Framework):

Set the project name and path:

The new projects are as follows:

Setup interface:

Set tbShow to read-only:

Second, single-thread port scanning 1. Write code

Double-click the button to write its click event:

Using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Net.Sockets;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Windows.Forms;namespace Scan {public partial class Form1: Form {/ / host address private string hostAddress; / / start port private int start; / / end port private int end / / Port number private int port; / / define thread object private Thread scanThread; public Form1 () {InitializeComponent () } private void button1_Click_1 (object sender, EventArgs e) {try {/ / initialize tbShow.Clear (); lb.Text = "0%"; / / get ip address and start and end number hostAddress = tbHost.Text Start = Int32.Parse (tbSPort.Text); end = Int32.Parse (tbEPort.Text); if (decideAddress ()) / / the port is reasonable {/ / make the input textbox read-only and cannot change tbHost.ReadOnly = true; tbSPort.ReadOnly = true TbEPort.ReadOnly = true; / / set the range of the progress bar pb.Minimum = start; pb.Maximum = end; / / the display box shows tbShow.AppendText ("Port Scanner v1.0.0" + Environment.NewLine + Environment.NewLine) / / call the port scan function PortScan ();} else {/ / if the port number is unreasonable, the pop-up window reports an error MessageBox.Show ("input error, port range is [0-65536]!") }} catch {/ / if the port number entered is non-integer, the pop-up window reports an error MessageBox.Show ("input error, port range is [0-65536]!") }} / determine whether the port is reasonable / private bool decideAddress () {/ / determine whether the port number is reasonable if ((start > = 0 & & start = 0 & & end)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report