1
입력 주소를 허용하는 기능을 추가하기 전에는 모두 정상적으로 작동합니다.Go - net.LookupAddr does not execute
IP-Addresse를 3 개의 세그먼트로 분할 한 후 getHostName
함수에 넘겨 주면 함수는 net.LookupAddr(ip)
을 호출 한 후에 함수의 "all/inclusive"를 건너 뜁니다.
package main
import (
"fmt"
"net"
"strconv"
"strings"
)
func getHostName(h chan string, ipAdresse string, n int) {
ip := ipAdresse + strconv.Itoa(n)
addr, ok := net.LookupAddr(ip)
fmt.Println(ok)
if ok == nil {
h <- ip + " - " + addr[0]
} else {
fmt.Println(ok)
}
}
func printer(n chan string) {
msg := <-n
fmt.Println(msg)
}
func main() {
fmt.Println("Please enter your local IP-Adresse e.g 192.168.1.1")
var ipAdresse_user string
fmt.Scanln(&ipAdresse_user)
ipsegment := strings.SplitAfter(ipAdresse_user, ".")
ipadresse_3 := ipsegment[0] + ipsegment[1] + ipsegment[2]
host := make(chan string)
for i := 0; i < 55; i++ {
go getHostName(host, ipadresse_3, i)
go printer(host)
}
fmt.Println("Finish - Network Scan")
}
WaitGroup을 사용하여 문제를 해결할 수 있습니다. http://golang.org/pkg/sync/#example_WaitGroup – Michael
다음과 같이 select 문을 시간 초과로 사용할 수 있습니다. http://play.golang.org/p/fSW0dMTABc – tiffon
답변 해 주셔서 감사합니다 :) –