{"id":13841785,"url":"https://github.com/XinRoom/go-portScan","last_synced_at":"2025-07-11T13:32:24.253Z","repository":{"id":49847754,"uuid":"425917693","full_name":"XinRoom/go-portScan","owner":"XinRoom","description":"High-performance port scanner. 高性能端口扫描器. syn scanner","archived":false,"fork":false,"pushed_at":"2024-11-08T05:07:52.000Z","size":442,"stargazers_count":278,"open_issues_count":2,"forks_count":40,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-11-08T06:18:47.977Z","etag":null,"topics":["fingerprint","ipv6","portscanner","syn","synscanner","webfinger"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/XinRoom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-08T16:45:16.000Z","updated_at":"2024-11-08T05:07:56.000Z","dependencies_parsed_at":"2024-03-21T10:19:13.723Z","dependency_job_id":"b9e096ac-60d8-4b49-a806-8dac300b78de","html_url":"https://github.com/XinRoom/go-portScan","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XinRoom%2Fgo-portScan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XinRoom%2Fgo-portScan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XinRoom%2Fgo-portScan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XinRoom%2Fgo-portScan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XinRoom","download_url":"https://codeload.github.com/XinRoom/go-portScan/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225729672,"owners_count":17515152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fingerprint","ipv6","portscanner","syn","synscanner","webfinger"],"created_at":"2024-08-04T17:01:21.162Z","updated_at":"2024-11-21T12:30:24.590Z","avatar_url":"https://github.com/XinRoom.png","language":"Go","funding_links":[],"categories":["信息搜集","Go"],"sub_categories":[],"readme":"# go-portScan\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/XinRoom/go-portScan.svg)](https://pkg.go.dev/github.com/XinRoom/go-portScan)\n\n高性能端口扫描器\n\nHigh-performance port scanner.\n\n\u003e *免责声明:*  \n\u003e 本工具由网络公开资料编写而成，仅进行网络信息状态验证，不具备侵害计算机系统的能力；若由本工具或衍生工具造成的任何直接或间接后果及损失，均由使用者本人负责，作者不承担任何责任。  \n\u003e *安全警示:*  \n\u003e 使用本工具必须遵守相关网络安全法律，禁止进行非授权的侵入性测试。\n\n## Feature\n\n- Syn stateless scan\n- Syn Automatic ARP detection on the Intranet\n- Scanning for large address segments has low occupancy (by iprange)\n- Scanning the address is shuffled\n- Concurrent high performance (by ants)\n- TCP scan\n- Port Fingerprint Identification\n- HTTP Service Detection\n\n## Use as a library\n\n### 1. SYN scanner\n\n```go\npackage main\n\nimport (\n\t\"github.com/XinRoom/go-portScan/core/host\"\n\t\"github.com/XinRoom/go-portScan/core/port\"\n\t\"github.com/XinRoom/go-portScan/core/port/syn\"\n\t\"github.com/XinRoom/iprange\"\n\t\"github.com/panjf2000/ants/v2\"\n\t\"log\"\n\t\"net\"\n\t\"sync\"\n\t\"time\"\n)\n\nfunc main() {\n\tsingle := make(chan struct{})\n\tretChan := make(chan port.OpenIpPort, 65535)\n\tgo func() {\n\t\tfor ret := range retChan {\n\t\t\tlog.Println(ret)\n\t\t}\n\t\tsingle \u003c- struct{}{}\n\t}()\n\n\t// 解析端口字符串并且优先发送 TopTcpPorts 中的端口, eg: 1-65535,top1000\n\tports, err := port.ShuffleParseAndMergeTopPorts(\"top1000\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// parse ip\n\tit, startIp, _ := iprange.NewIter(\"1.1.1.1/30\")\n\n\t// scanner\n\tss, err := syn.NewSynScanner(startIp, retChan, syn.DefaultSynOption)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// port scan func\n\tportScan := func(ip net.IP) {\n\t\tfor _, _port := range ports { // port\n\t\t\tss.WaitLimiter()\n\t\t\tss.Scan(ip, _port, port.IpOption{}) // syn 不能并发，默认以网卡和驱动最高性能发包\n\t\t}\n\t}\n\n\t// Pool - ping and port scan\n\tvar wgPing sync.WaitGroup\n\tpoolPing, _ := ants.NewPoolWithFunc(50, func(ip interface{}) {\n\t\t_ip := ip.(net.IP)\n\t\tif host.IsLive(_ip.String(), true, 800*time.Millisecond) {\n\t\t\tportScan(_ip)\n\t\t}\n\t\twgPing.Done()\n\t})\n\tdefer poolPing.Release()\n\n\tstart := time.Now()\n\tfor i := uint64(0); i \u003c it.TotalNum(); i++ { // ip索引\n\t\tip := make(net.IP, len(it.GetIpByIndex(0)))\n\t\tcopy(ip, it.GetIpByIndex(i)) // Note: dup copy []byte when concurrent (GetIpByIndex not to do dup copy)\n\t\twgPing.Add(1)\n\t\tpoolPing.Invoke(ip)\n\t}\n\n\twgPing.Wait()\n\tss.Wait()\n\tss.Close()\n\t\u003c-single\n\tlog.Println(time.Since(start))\n}\n```\n\n### 2. TCP scanner\n\n```go\npackage main\n\nimport (\n\t\"github.com/XinRoom/go-portScan/core/host\"\n\t\"github.com/XinRoom/go-portScan/core/port\"\n\t\"github.com/XinRoom/go-portScan/core/port/tcp\"\n\t\"github.com/XinRoom/iprange\"\n\t\"github.com/panjf2000/ants/v2\"\n\t\"log\"\n\t\"net\"\n\t\"sync\"\n\t\"time\"\n)\n\nfunc main() {\n\tsingle := make(chan struct{})\n\tretChan := make(chan port.OpenIpPort, 65535)\n\tgo func() {\n\t\tfor ret := range retChan {\n\t\t\tlog.Println(ret)\n\t\t}\n\t\tsingle \u003c- struct{}{}\n\t}()\n\n\t// 解析端口字符串并且优先发送 TopTcpPorts 中的端口, eg: 1-65535,top1000\n\tports, err := port.ShuffleParseAndMergeTopPorts(\"top1000\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// parse Ip\n\tit, _, _ := iprange.NewIter(\"1.1.1.1/30\")\n\n\t// scanner\n\tss, err := tcp.NewTcpScanner(retChan, tcp.DefaultTcpOption)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// port scan func\n\tportScan := func(ip net.IP) {\n\t\tfor _, _port := range ports { // port\n\t\t\tss.WaitLimiter()\n\t\t\tss.Scan(ip, _port, port.IpOption{}) // syn 不能并发，默认以网卡和驱动最高性能发包\n\t\t}\n\t}\n\n\t// Pool - ping and port scan\n\tvar wgPing sync.WaitGroup\n\tpoolPing, _ := ants.NewPoolWithFunc(50, func(ip interface{}) {\n\t\t_ip := ip.(net.IP)\n\t\tif host.IsLive(_ip.String(), true, 800*time.Millisecond) {\n\t\t\tportScan(_ip)\n\t\t}\n\t\twgPing.Done()\n\t})\n\tdefer poolPing.Release()\n\n\tstart := time.Now()\n\tfor i := uint64(0); i \u003c it.TotalNum(); i++ { // ip索引\n\t\tip := make(net.IP, len(it.GetIpByIndex(0)))\n\t\tcopy(ip, it.GetIpByIndex(i)) // Note: dup copy []byte when concurrent (GetIpByIndex not to do dup copy)\n\t\twgPing.Add(1)\n\t\tpoolPing.Invoke(ip)\n\t}\n\n\twgPing.Wait()\n\tss.Wait()\n\tss.Close()\n\t\u003c-single\n\tlog.Println(time.Since(start))\n}\n```\n\n### 3. Http/Port Finger\nHttp Web Cms Finger\n```go\n// \"github.com/XinRoom/go-portScan/core/port/fingerprint\"\nfunc ProbeHttpInfo(host string, _port uint16, dialTimeout time.Duration) (httpInfo *port.HttpInfo, banner []byte, isDailErr bool) {}\nfunc WebHttpInfo(url2 string, dialTimeout time.Duration) (httpInfo *port.HttpInfo, banner []byte, isDailErr bool) {}\n\n// \"github.com/XinRoom/go-portScan/core/port/fingerprint/webfinger\"\nfunc WebFingerIdent(resp *http.Response) (names []string) {}\n```\nTcp Port Service Finger\n\n```go\n// \"github.com/XinRoom/go-portScan/core/port/fingerprint\"\nfunc PortIdentify(network string, ip net.IP, _port uint16, dailTimeout time.Duration) (serviceName string, banner []byte, isDailErr bool) {}\n```\n\n### 4. For More\n\nTo see [./cmd/go-portScan.go](./cmd/go-portScan.go)\n\n## Cmd Build\n\n普通编译\n\n```\ngit clone https://github.com/XinRoom/go-portScan\ncd go-portScan\ngo get -d -u ./...\ngo build -trimpath -ldflags=\"-s -w\" -tags urfave_cli_no_docs cmd/go-portScan.go\n```\n\nLinux静态链接编译（需要docker环境）\n\n```\nsh ./build/build_static_alpine.sh\n```\n\n禁用syn模块，只保留tcp的编译(以便能在未安装pcap的windows机子上运行)\n\n```\ngo build -trimpath -ldflags=\"-s -w\" -tags urfave_cli_no_docs,nosyn cmd/go-portScan.go\n```\n\n## Cmd Usage\n\n`.\\go-portScan.exe -ip 1.1.1.1/30 [-p str] [-Pn] [-sT] [-sV] [-httpx] [-rate num] [-rateP num] [-timeout num(ms)]`\n\n```\nNAME:\n   PortScan - A new cli application\n\nUSAGE:\n   PortScan [global options] command [command options] [arguments...]\n\nDESCRIPTION:\n   High-performance port scanner\n\nCOMMANDS:\n   help, h  Shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --ip value                        target ip, eg: \"1.1.1.1/30,1.1.1.1-1.1.1.2,1.1.1.1-2\"\n   --iL value                        target ip file, eg: \"ips.txt\"\n   --port value, -p value            eg: \"top1000,5612,65120,-\" (default: \"top1000\")\n   --Pn                              no ping probe (default: false)\n   --rateP value, --rp value         concurrent num when ping probe each ip (default: 300)\n   --PT                              use TCP-PING mode (default: false)\n   --sT                              TCP-mode (default: false)\n   --timeout value, --to value       TCP-mode SYN-mode timeout. unit is ms. (default: 800)\n   --sS                              Use SYN-mode(default: true)\n   --nexthop value, --nh value       specified nexthop gw add to pcap dev\n   --rate value, -r value            number of packets sent per second. If set -1, TCP-mode is 1000, SYN-mode is 1500(SYN-mode is restricted by the network adapter, 2000=1M) (default: -1)\n   --devices, --ld                   list devices name (default: false)\n   --sV                              port service identify (default: false)\n   --httpx                           http server identify (default: false)\n   --netLive                         Detect live C-class networks, eg: -ip 192.168.0.0/16,172.16.0.0/12,10.0.0.0/8 (default: false)\n   --maxOpenPort value, --mop value  Stop the ip scan, when the number of open-port is maxOpenPort (default: 0)\n   --oCsv value, --oC value          output csv file\n   --oFile value, -o value           output to file\n   --help, -h                        show help (default: false)\n```\n\n关键参数说明：\n\n```\n--Pn 在目标禁止PING时使用\n--rate 在网络不稳定时（互联网）可以适当减少（互联网下建议500~1500）\n--timeout 在网络不稳定时（互联网）可以适当增加\n--nexthop 用于在syn扫描模式下，找不到路由网卡情况时，指定下一跳网关地址（需要是本地网卡上绑定的网关地址）\n--PT ICMP不通时，使用常见端口的TCP探测主机是否存活\n\n--sV 用于判断端口的服务（主要是探测风险比较大的服务）\n--netLive 用于抽取网络内6个左右IP进行存活探测\n--httpx 用于探测http服务的title等信息\n--mop 用于目标组内存在防扫描防火墙的情况，单个IP扫描到开放的端口到达该值就停止对该IP扫描，避免浪费时间（建议值500）\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXinRoom%2Fgo-portScan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FXinRoom%2Fgo-portScan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXinRoom%2Fgo-portScan/lists"}