mirror of
https://github.com/openziti/zrok.git
synced 2025-01-23 06:19:04 +01:00
18 lines
339 B
Go
18 lines
339 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
func AutoListener(address string, startPort, endPort uint16) (net.Listener, error) {
|
|
for i := startPort; i <= endPort; i++ {
|
|
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", address, i))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
return l, nil
|
|
}
|
|
return nil, fmt.Errorf("no listener found in range")
|
|
}
|