NAME
Net::EmptyPort - find a free TCP port
SYNOPSIS
use Net::EmptyPort qw(empty_port check_port);
# get a random free port
my $port = empty_port();
# check if a port is already used
if (check_port(5000)) {
say "Port 5000 already in use";
}
DESCRIPTION
Net::EmptyPort helps finding an empty TCP port.
METHODS
- empty_port
-
my $port = empty_port();
Get the available port number, you can use.
Normally, empty_port() finds empty port number from 49152..65535. See http://www.iana.org/assignments/port-numbers
But you want to use another range, use a following form:
# 5963..65535 my $port = empty_port(5963);
- check_port
-
my $true_or_false = check_port(5000);
Checks if the given port is already in use. Returns true if it is in use (i.e. if the port is NOT free). Returns false if the port is free.
AUTHOR
Tokuhiro Matsuno <tokuhirom@gmail.com>
THANKS TO
kazuhooku
dragon3
charsbar
Tatsuhiko Miyagawa
lestrrat
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.