anvie / port-scanner

Simple port scanner library for Go
104 stars 20 forks source link

Fix to few values innitialised #4

Closed combor closed 8 years ago

combor commented 8 years ago

What

While testing port scanner with go1.6 I discovered that it fails with initialising PortScanner struct. It throws such error:

combor/port-scanner/PortScanner.go:27: too few values in struct initializer
combor/port-scanner/PortScanner.go:50: cannot use h.timeout (type int) as type time.Duration in argument to net.DialTimeout
combor/port-scanner/PortScanner.go:82: cannot use h.timeout (type int) as type time.Duration in argument to net.DialTimeout

Additionaly there is a wrong type returned in openConn method:

combor/port-scanner/PortScanner.go:90: cannot use conn (type net.Conn) as type *net.TCPConn in return argument: need type assertion

How to test

Run the code from README but with modified call to NewPortScanner :

  timeout := 100 * time.Millisecond
  ps := portscanner.NewPortScanner(host, timeout)

  // get opened port
  fmt.Printf("scanning port %d-%d...\n", 20, 65535)

  openedPorts := ps.GetOpenedPort(20, 30000)

  for i := 0; i < len(openedPorts); i++ {
    port := openedPorts[i]
    fmt.Print(" ", port, " [open]")
    fmt.Println("  -->  ", ps.DescribePort(port))
  }
anvie commented 8 years ago

Thanks for your contribution! 👍