24
contributi
(Aggiunto template autori) |
(Aggiornato script) |
||
Riga 63: | Riga 63: | ||
# # | # # | ||
#################################################################################### | #################################################################################### | ||
# ultima modifica: | # ultima modifica: 29/11/2011 | ||
use strict; | use strict; | ||
my $interface = shift | my $interface = shift; | ||
my $interface2 = shift; | |||
my @knownNetwork = ""; | my @knownNetwork = ""; | ||
Riga 74: | Riga 75: | ||
my $knownNetwork; | my $knownNetwork; | ||
my @iwlist = ""; | my @iwlist = ""; | ||
my $link = ""; | |||
my $i = 0; | |||
if ($interface eq "-h" or $interface eq "--help") { | $interface = "wlan0" unless $interface; | ||
print "USO: wifiup.pl | $interface2 = "eth0" unless $interface2; | ||
if ($interface eq "-h" or $interface eq "--help" or !$interface2) { | |||
print "USO: wifiup.pl [interfaccia_wifi [interfaccia_eth]]\nOPZIONI:\n\t--h --help\tVisualizza questo messaggio\n"; | |||
exit 0; | exit 0; | ||
} | } | ||
Riga 82: | Riga 87: | ||
die "ERRORE: L\'interfaccia $interface non fa riferimento ad un dispositivo wifi\n" if ( `iwconfig $interface 2>&1` !~ /ESSID/ ); | die "ERRORE: L\'interfaccia $interface non fa riferimento ad un dispositivo wifi\n" if ( `iwconfig $interface 2>&1` !~ /ESSID/ ); | ||
foreach (`grep iface /etc/network/interfaces`) { | foreach (`grep ^iface /etc/network/interfaces`) { | ||
push(@knownNetwork,$1) if /iface\s+(.*)\s+inet/; | push(@knownNetwork,$1) if /iface\s+(.*)\s+inet/; | ||
} | } | ||
system("ifconfig $interface up"); | system("ifconfig $interface up"); | ||
push(@iwlist,$_) foreach (`iwlist $interface scan | grep ESSID`); | |||
foreach $knownNetwork (@knownNetwork) { | for ($i=1; $i<11; $i++) { | ||
@iwlist = ""; | |||
push(@iwlist,$_) foreach (`iwlist $interface scan | grep ESSID`); | |||
foreach $knownNetwork (@knownNetwork) { | |||
foreach (@iwlist) { | |||
$foundNetwork = $knownNetwork if /$knownNetwork/; | |||
} | |||
} | |||
if ($foundNetwork eq "") { | |||
print "wifiup.pl: Nessuna rete wifi conosciuta al tentativo $i\n"; | |||
sleep 2; | |||
} else { | |||
$i = 11; | |||
} | } | ||
} | } | ||
if ($foundNetwork eq "") { | if ($foundNetwork eq "") { | ||
print "wifiup.pl: Nessuna rete wifi conosciuta.\n"; | print "wifiup.pl: Nessuna rete wifi conosciuta.\n"; | ||
$link = `ethtool $interface2 | grep "Link detected" | cut -d " " -f 3`; | |||
chomp $link; | |||
if ($link eq "yes") { | |||
print "wifiup.pl: Acquisizione dell'indirizzo di rete per $interface2.\n"; | |||
system ("dhclient $interface2"); | |||
} | |||
} else { | } else { | ||
print "wifiup.pl: Configuro $interface per la rete $foundNetwork.\n"; | print "wifiup.pl: Configuro $interface per la rete $foundNetwork.\n"; | ||
system("ifup $interface=$foundNetwork"); | system("ifup $interface=$foundNetwork"); | ||
} | } | ||
</pre> | </pre> | ||
Rendiamo <code>wifiup.pl</code> eseguibile con | Rendiamo <code>wifiup.pl</code> eseguibile con |
contributi