Go學習——網絡

端口掃描:tcp

package main

import (
	"fmt"
	"net"
	"strconv"
)

func main() {
	service := "localhost:"
	//從1號端口掃描到1000號
	for port := 1; port < 1000; port++ {
		_, err := net.DialTimeout("tcp", service+strconv.Itoa(port), 1000000000) //鏈接時間爲1秒超過1秒視爲失敗
		if err == nil {
			fmt.Println(port)
		}
	}
}
相關文章
相關標籤/搜索