GithubHelp home page GithubHelp logo

go-tcp-scanner's Introduction

一个简单的端口扫描器

自己也经常搭一些服务器之类的东西,有时需要查看一下端口开放情况。网上搜了一下太乱了,大多数网页的那种不能批量扫描,又或者是要收费,而且我也不需要很复杂的功能,因此自己简单写了一个。

使用方法:程序打包成可执行文件以tcp-scanner命名为例,执行命令tcp-scanner 127.0.0.1 1 10000,第一个参数为要扫描的ip,第二个参数为起始端口号,第三个参数为终止端口号。

思路:使用net.Dial("tcp", address)进行端口扫描,当返回结果中error为空时即为本次扫描地端口为开放,但是使用单线程进行扫描效率极低。 因此需要用goroutine并发地进行端口扫描,而当单次扫描端口数量过多(达到几亿以上地时候)创建大量goroutine会因系统资源不足而卡死(当然扫个端口不会需要这么高并发😂)。 为了避免这种情况,使用channel缓冲区来实现。创建固定数量的goroutine,然后通过channel向其中发送需要扫描的端口号。 而每当一个goroutine扫描结束后再通过一个channel将扫描结果返回,失败返回0,成功则返回端口号,统计不为0的结果,最后输出。

go-tcp-scanner's People

Contributors

ormissia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.