Win32-Wlan

 view release on metacpan or  search on metacpan

lib/Win32/Wlan.pm  view on Meta::CPAN

    if ($wlan->available) {
        print "Connected to ", $wlan->connection->{profile_name},"\n";
        print "I see the following networks\n";
        for ($wlan->visible_networks) {
            printf "%s\t-%d dbm\n", $_->{name}, $_->{signal_quality};
        };

    } else {
        print "No Wlan detected (or switched off)\n";
    };

=head1 METHODS

=head2 C<< Win32::Wlan->new( %args ) >>

    my $wlan = Win32::Wlan->new();

Creates a new Win32::Wlan object.

=over 4

=item *

C<available> - optional argument to force detection of general Wlan availability

=item *

C<handle> - optional argument to give an existing Wlan handle to the object

=item *

C<interface> - optional argument to give an existing guuid to the object

=back

=cut

sub new {
    my ($class,%args) = @_;

    if ($args{ available } or !exists $args{ available }) {
        if (! $args{handle}) {
            $args{handle} = eval { WlanOpenHandle() };
            $args{available} = $wlan_available;
        } else {
            #
            # User gave a handle, so assume availibility is true
            #
            $args{available} = 1;
        }
        if ($args{available}) {
            if (! $args{ interface }) {
                my @interfaces = WlanEnumInterfaces($args{handle});
                if (@interfaces > 1) {
                    warn "More than one Wlan interface found. Using first.";
                }
                $args{interface} = $interfaces[0];
            }
        }
    }
    bless \%args => $class;
};


sub DESTROY {
    my ($self) = @_;
    if ($self->handle and $self->available) {
        WlanCloseHandle($self->handle);
    };
}

=head2 C<< $wlan->handle >>

Returns the Windows API handle for the Wlan API.

=cut

sub handle { $_[0]->{handle} };

=head2 C<< $wlan->interface >>

    print $wlan->interface->{name};

Returns a hashref describing the interface. The keys are
C<guuid> for the guuid, C<name> for the human-readable name and
C<status> for the status of the interface.

=cut

sub interface { $_[0]->{interface} };

=head2 C<< $wlan->available >>

    $wlan->available
        or warn "Wlan API is not available";

Returns whether the Wlan API is available. The Wlan API is available
on Windows XP SP3 or higher.

=cut

sub available { $_[0]->{available} };

=head2 C<< $wlan->connected >>

    $wlan->connected
        or warn "Wlan connection unavailable";

Returns whether a Wlan connection is established. No connection is established
when Wlan is switched off or no access point is in range.

=cut

sub connected {
    my $conn = $_[0]->connection;
    defined $conn->{profile_name} && $conn->{profile_name}
};

=head2 C<< $wlan->connection >>

    if ($wlan->connected) {

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.526 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )