Skip to content

hamzaplojovic/freeport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

freeport

Find free ports on your machine.

Install

Homebrew:

brew install hamzaplojovic/tap/freeport

Go:

go install github.com/hamzaplojovic/freeport@latest

Binary:

Download the latest binary from GitHub Releases.

Usage

Get a free port:

$ freeport
54321

Get multiple free ports:

$ freeport -count 3
54321
54322
54323

Find a free port in a specific range:

$ freeport -range 8000-9000
8042

Check if a port is free:

$ freeport -check 3000
Port 3000 is free

$ freeport -check 3000
Port 3000 is taken
# exit code 1

JSON output:

$ freeport -json
{"port":54321}

$ freeport -count 3 -json
{"ports":[54321,54322,54323]}

$ freeport -check 3000 -json
{"free":true,"port":3000}

Flags

Flag Description
-count N Number of free ports to find (default: 1)
-range LOW-HIGH Find a free port within a range
-check PORT Check if a specific port is free (exit 0) or taken (exit 1)
-json Output in JSON format
-version Print version

Why

Every time I need to check if a port is available, I end up typing lsof -i :PORT and parsing the output in my head. Or I need a free port for a script and have to write the same "bind to :0" snippet again. This is just a small tool that does one thing and does it fast.

License

MIT

About

Find free ports on your machine

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages