LoginSignup
5
5

More than 5 years have passed since last update.

使ってないポートを取得する (Perl)

Last updated at Posted at 2012-03-16

ref: 使ってないポートを取得する

#!/usr/bin/env perl
use strict;
use warnings;
use v5.14;
use IO::Socket::INET;

sub empty_port () {
    my $sock = IO::Socket::INET->new(
        Prot   => 'tcp',
        Listen => 1,
        (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
    );
    my $port = $sock->sockport;
    $sock->close;
    $port;
}

say empty_port;
5
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5