forked from dbb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwifi-switch.pl
executable file
·56 lines (43 loc) · 1.07 KB
/
wifi-switch.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use File::Copy;
# Options #######################################
my $file = "interfaces";
my $primary_id = 'wpa-ssid primid';
my $primary_pass = 'wpa-psk primpass';
my $secondary_id = 'wpa-ssid secid';
my $secondary_pass = 'wpa-psk secpass';
# End Options ###################################
open( my $in, "<", $file );
open( my $out, ">", "$file.tmp" );
my $target = $ARGV[0]
or die "Must supply '1' or '2' as the target network.\n";
if ( $target == 1 ) {
&set_primary();
}
elsif ( $target == 2 ) {
&set_secondary();
}
else {
print "Invalid network selection.\n";
}
sub set_primary {
while ( <$in> ) {
s/$secondary_id/$primary_id/;
s/$secondary_pass/$primary_id/;
print $out $_;
}
} # end &set_primary
sub set_secondary {
while ( <$in> ) {
s/$primary_id/$secondary_id/;
s/$primary_pass/$secondary_id/;
print $out $_;
}
} # end &set_secondary
move( $file, "$file.orig" );
move( "$file.tmp", $file );
close $in;
close $out;