zrok/agent/autoListener.go
2024-11-06 17:18:20 -05:00

18 lines
340 B
Go

package agent
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")
}