zoukankan      html  css  js  c++  java
  • 扫描计算机的端口号

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 扫描计算机的端口号
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
                if (string.IsNullOrEmpty(textBox1.Text.Trim())||string.IsNullOrEmpty(textBox2.Text.Trim())||string.IsNullOrEmpty(textBox3.Text.Trim()))
                {
                    MessageBox.Show("输入端口号和IP地址。。。","提示");
                    return;
                }
                IPAddress ip = IPAddress.Parse(textBox3.Text.Trim());//通过IP字符串实例化IPAddress类
                for (int i =Convert.ToInt32(textBox1.Text); i < Convert.ToInt32(textBox2.Text)+1; i++)
                {
                    TcpClient tx = new TcpClient();//实例化
                    try
                    {
                        tx.Connect(ip, i);//使用IP地址和端口号连接主机。
                        listBox1.Items.Add("COM:" + i + "是开放的.");
                    }
                    catch { }
    
                     finally {tx.Close();//释放该实例,但不关闭基础连接。}
                       
                }
                listBox1.Items.Add("扫描结束!");
            }
        }
    }

  • 相关阅读:
    Springboot配置多数据源Rabbitmq
    SpringBoot 搭建 Rabbitmq
    SpringBoot 成Rabbitmq的疑惑记录
    Docker安装Redis关于Mounts denied解决
    使用Preferences写入注册表
    RSA解密报错 javax.crypto.BadPaddingException: Decryption error
    星座和生肖转化
    bio与nio
    跳表
    springboot+dubbo+zookeeper
  • 原文地址:https://www.cnblogs.com/jason-davis/p/4041811.html
Copyright © 2011-2022 走看看