使用golang制作端口扫描器

本文介绍如何利用Golang创建一个端口扫描器。通过指定协议(默认TCP)、CPU数量和线程数来定制扫描。同时,文章还讨论了单个端口扫描的超时控制,超时默认设置为5秒,以提高扫描效率。
摘要由CSDN通过智能技术生成

使用方法:command [options] addr
options:
-p    使用指定协议,如:tcp、udp,默认为tcp
-c    使用指定cpu数量,默认为1
-t     使用指定线程数,默认为1(使用多线程扫描,速度会更快)

-d    扫描单个端口超时控制,单位:秒,默认为5秒

package main

import (
	"fmt"
	"net"
	"time"
	"sync"
	"flag"
	"os"
	"runtime"
)

type PortScan struct {
	timeOut       time.Duration
	protocol      string
	cores         int
	threads       int
	addr          string
	availablePort []int
	wasteTime     int64
	rwLocker      sync.RWMutex
}

var protocol = flag.String("p", "tcp", "Use the specified protocol")
var cores = flag.Int("c", 1, "Use the specified core number")
var threads = flag.Int("t", 0, "Use the specified thread number")
var timeout = flag.Int("d", 5, "Use the specifi
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值