#!/usr/bin/perl # V 1.0 # Cell 01 - Address: 00:1E:2A:10:E5:9F # ESSID:"stella" # Mode:Master # Frequency:2.437 GHz (Channel 6) # Quality=42/94 Signal level=-53 dBm Noise level=-95 dBm # Encryption key:on # Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s # 12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s # 48 Mb/s; 54 Mb/s # Extra:bcn_int=100 sub ScanWifi () { $cell="none"; $cellinfo=""; open (NISUSER, 'iwlist eth1 scanning|') || die "could not get list of SSID"; while () { if (/^\s*(Cell [0-9]+) - Address: (..:..:..:..:..:..).*$/) { if ($1 ne $cell) { $cell=$1; $cellinfo="$1-$2"; } } elsif (/^\s*ESSID:\"(.*)\"$/) { $cellinfo="$1-".$cellinfo; } elsif (/^\s*Encryption key:(.*)$/) { $cellinfo=$cellinfo."-$1"; push @wifi, $cellinfo; } } # push @wifi, "wired-dhcp"; close NISUSER; } sub ListWifi(){ # Cell 01-00:1E:2A:10:E5:9F-"stella" for ($i = 0 ; $i <= $#wifi; $i++) { print $i.".".$wifi[$i]."\n"; } } sub Conn($@){ my ($path_script,@wifi)=@_; @line=split(/-/, $wifi[$sel]); if (-e "$path_script/$line[0]"){ system("sh $path_script/$line[0]") == 0 or die "system @args failed: $?"; } else { print "configuration file $line[0] not present\n"; } } sub main { @wifi = (); $#wifi = -1; my $eth_wifi="eth1"; my $path_script="/opt/bin/wirenet"; my $test=0; open (TEST, 'ifconfig -a |') || die "I can not do 'ifconfig -a' "; while () { if (/^eth1.*$/) { $test=1; } } close (TEST); if ($test){ system("ifconfig $eth_wifi up") == 0 or die "system @args failed: $?"; ScanWifi(); } # print "Attach the wireless card and press Enter\n"; # $sel = <>; push @wifi, "wired-dhcp"; ListWifi(); $sel=-1; while (($sel < 0)||($sel > $#wifi)||($sel eq "")){ print "Select the network\n"; chomp ($sel = <>); $sel =~ s/^\s+//; $sel =~ s/\s+$//; } Conn($path_script,@wifi); } main();