line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::Wlan; |
2
|
1
|
|
|
1
|
|
714
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
3
|
1
|
|
|
1
|
|
8
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
4
|
1
|
|
|
|
|
198
|
use Win32::Wlan::API qw< |
5
|
|
|
|
|
|
|
WlanOpenHandle |
6
|
|
|
|
|
|
|
WlanCloseHandle |
7
|
|
|
|
|
|
|
WlanQueryCurrentConnection |
8
|
|
|
|
|
|
|
WlanEnumInterfaces |
9
|
|
|
|
|
|
|
WlanGetAvailableNetworkList |
10
|
|
|
|
|
|
|
$wlan_available |
11
|
1
|
|
|
1
|
|
605
|
>; |
|
1
|
|
|
|
|
3
|
|
12
|
1
|
|
|
1
|
|
6
|
use vars qw<$VERSION>; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
486
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.06'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Ideally, the handle should be (another) singleton |
16
|
|
|
|
|
|
|
# that fetches and keeps the handle until the application |
17
|
|
|
|
|
|
|
# closes or the last Win32::Wlan object gets destroyed |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Win32::Wlan - Query wlan properties |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
require Win32::Wlan; |
26
|
|
|
|
|
|
|
my $wlan = Win32::Wlan->new; |
27
|
|
|
|
|
|
|
if ($wlan->available) { |
28
|
|
|
|
|
|
|
print "Connected to ", $wlan->connection->{profile_name},"\n"; |
29
|
|
|
|
|
|
|
print "I see the following networks\n"; |
30
|
|
|
|
|
|
|
for ($wlan->visible_networks) { |
31
|
|
|
|
|
|
|
printf "%s\t-%d dbm\n", $_->{name}, $_->{signal_quality}; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} else { |
35
|
|
|
|
|
|
|
print "No Wlan detected (or switched off)\n"; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 C<< Win32::Wlan->new( %args ) >> |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $wlan = Win32::Wlan->new(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Creates a new Win32::Wlan object. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
C - optional argument to force detection of general Wlan availability |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item * |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
C - optional argument to give an existing Wlan handle to the object |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item * |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
C - optional argument to give an existing guuid to the object |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=back |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
0
|
|
|
0
|
1
|
|
my ($class,%args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
0
|
|
|
|
if ($args{ available } or !exists $args{ available }) { |
68
|
0
|
|
0
|
|
|
|
$args{available} ||= $wlan_available; |
69
|
0
|
|
0
|
|
|
|
$args{handle} ||= WlanOpenHandle(); |
70
|
0
|
0
|
|
|
|
|
if (! $args{ interface }) { |
71
|
0
|
|
|
|
|
|
my @interfaces = WlanEnumInterfaces($args{handle}); |
72
|
0
|
0
|
|
|
|
|
if (@interfaces > 1) { |
73
|
0
|
|
|
|
|
|
warn "More than one Wlan interface found. Using first."; |
74
|
|
|
|
|
|
|
}; |
75
|
0
|
|
|
|
|
|
$args{interface} = $interfaces[0]; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
}; |
78
|
0
|
|
|
|
|
|
bless \%args => $class; |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub DESTROY { |
82
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
83
|
0
|
0
|
0
|
|
|
|
if ($self->handle and $self->available) { |
84
|
0
|
|
|
|
|
|
WlanCloseHandle($self->handle); |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 C<< $wlan->handle >> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns the Windows API handle for the Wlan API. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
|
sub handle { $_[0]->{handle} }; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 C<< $wlan->interface >> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
print $wlan->interface->{name}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Returns a hashref describing the interface. The keys are |
101
|
|
|
|
|
|
|
C for the guuid, C for the human-readable name and |
102
|
|
|
|
|
|
|
C for the status of the interface. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
0
|
1
|
|
sub interface { $_[0]->{interface} }; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 C<< $wlan->available >> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$wlan->available |
111
|
|
|
|
|
|
|
or warn "Wlan API is not available"; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Returns whether the Wlan API is available. The Wlan API is available |
114
|
|
|
|
|
|
|
on Windows XP SP3 or higher. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
1
|
|
sub available { $_[0]->{available} }; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 C<< $wlan->connected >> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$wlan->connected |
123
|
|
|
|
|
|
|
or warn "Wlan connection unavailable"; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns whether a Wlan connection is established. No connection is established |
126
|
|
|
|
|
|
|
when Wlan is switched off or no access point is in range. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub connected { |
131
|
0
|
|
|
0
|
1
|
|
my $conn = $_[0]->connection; |
132
|
0
|
0
|
|
|
|
|
defined $conn->{profile_name} && $conn->{profile_name} |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 C<< $wlan->connection >> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
if ($wlan->connected) { |
138
|
|
|
|
|
|
|
print "Connected to "; |
139
|
|
|
|
|
|
|
print $wlan->connection->{profile_name}; |
140
|
|
|
|
|
|
|
}; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns information about the current connection in a hashref. The keys |
143
|
|
|
|
|
|
|
are |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over 4 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
C - the name of the profile of the current connection |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub connection { |
156
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
157
|
0
|
0
|
|
|
|
|
if ($self->available) { |
158
|
0
|
|
|
|
|
|
return { WlanQueryCurrentConnection( $self->handle, $self->interface->{guuid} ) }; |
159
|
|
|
|
|
|
|
}; |
160
|
|
|
|
|
|
|
}; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 C<< $wlan->visible_networks >> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns information about the currently visible networks as a list of |
165
|
|
|
|
|
|
|
hashrefs. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
C - the SSID of the network |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
C - the signal quality ranging linearly from 0 to 100 |
176
|
|
|
|
|
|
|
meaning -100 dbm to -50 dbm |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=back |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub visible_networks { |
183
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
184
|
0
|
0
|
|
|
|
|
if ($self->available) { |
185
|
0
|
|
|
|
|
|
return WlanGetAvailableNetworkList( $self->handle, $self->interface->{guuid} ); |
186
|
|
|
|
|
|
|
}; |
187
|
|
|
|
|
|
|
}; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
__END__ |