https://github.com/projectdiscovery/freeport
Free listening port from the OS
https://github.com/projectdiscovery/freeport
Last synced: over 1 year ago
JSON representation
Free listening port from the OS
- Host: GitHub
- URL: https://github.com/projectdiscovery/freeport
- Owner: projectdiscovery
- License: mit
- Created: 2022-10-04T19:33:25.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-25T01:50:22.000Z (over 1 year ago)
- Last Synced: 2025-03-29T23:08:56.202Z (over 1 year ago)
- Language: Go
- Size: 51.8 KB
- Stars: 30
- Watchers: 13
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# freeport
Extended and revisited version of `https://github.com/phayes/freeport` - Get a free port from the OS.
```go
...
tcpPort, err := freeport.GetFreePort("127.0.0.1", freeport.TCP)
if err != nil {
panic(err)
}
fmt.Println("TCP port: ", tcpPort.Port)
fmt.Println("Multiple ports:")
// get multiple ports
// test with TCP
tcpPorts, err := freeport.GetFreePorts("127.0.0.1", freeport.TCP, 5)
if err != nil {
panic(err)
}
for _, port := range tcpPorts {
fmt.Println("TCP port: ", port.Port)
}
...
```
output:
```
Single port:
UDP port: 57224
TCP port: 51655
Multiple ports:
TCP port: 51656
TCP port: 51657
TCP port: 51658
TCP port: 51659
TCP port: 51660
```
# License
freeport is distributed under MIT License