Skip to content

Commit 4a703d1

Browse files
committed
[+] binder [+]
1 parent 27d73d6 commit 4a703d1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/binder/binder.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package binder
22

33
import (
4+
"fmt"
45
"net"
56

7+
"github.com/phayes/freeport"
68
"github.com/projectdiscovery/gologger"
79
)
810

@@ -16,3 +18,17 @@ func CanListenOn(address string) bool {
1618
}
1719
return true
1820
}
21+
22+
func GetRandomListenAddress(currentAddress string) (string, error) {
23+
addrOrig, _, err := net.SplitHostPort(currentAddress)
24+
if err != nil {
25+
return "", err
26+
}
27+
28+
newPort, err := freeport.GetFreePort()
29+
if err != nil {
30+
return "", err
31+
}
32+
33+
return net.JoinHostPort(addrOrig, fmt.Sprintf("%d", newPort)), nil
34+
}

0 commit comments

Comments
 (0)