This is a creation in Article, where the information may have evolved or changed.
This code is mainly from the network, the source code has problems, has now been fixed, can be directly compiled to run
Package Mainimport ("NET" "FMT" "OS" "Runtime" "Time" "StrConv") func loops (startport, Endport int, inport Chan int) {for I: = St Artport; I <= Endport; I++{inport <-I}}func Scanner (InPort, outport, out Chan int, IP net. IP, Endport int) {for{in: = <-inporttcpaddr: = &net. Tcpaddr{ip:ip,port:in}conn, err: = Net. DIALTCP ("TCP", nil, tcpaddr) if err! = Nil {outport <-0}else{outport <-in Conn. Close ()}if in = = Endport{out <-in}}}func Main () {runtime. Gomaxprocs (4) InPort: = make (chan int) StartTime: = time. Now (). Unix () Outport: = make (chan int) out: = Make (chan int) Collect: = []int{}if len (OS). Args)! = 4 {fmt. Println ("Usage:scanner.exe IP startport endport") fmt. PRINTLN ("Endport must be larger than Startport") os. Exit (0)}ip: = Net. PARSEIP (OS. ARGS[1]) if (OS. ARGS[3] < OS. Args[2]) {FMT. Println ("Usage:scanner IP startport endport") fmt. PRINTLN ("Endport must be larger than Startport") os. Exit (0)}fmt. Printf ("The IP is%s \ r \ n", IP) startport, _:= StrConv. Atoi (OS. ARGS[2]) Endport, _: = StrcoNv. Atoi (OS. ARGS[3]) fmt. Printf ("%d---------%d\r\n", Startport,endport) go Loop (Startport, Endport, InPort) for{select {case <-out:fmt. PRINTLN (collect) Endtime: = time. Now (). Unix () fmt. PRINTLN ("The scan process has spent", Endtime-starttime, "second") OS. Exit (0) Default:go scanner (InPort, outport, out, IP, endport) port: = <-outportif Port! = 0{collect = Append (Collect, PO RT)}}}