Friday, September 25, 2009

Wireless Chanel list in Ubuntu

Step 1: Install/Enable your Wireless Card

Step 2: Scan the media using 'iwlist scan'
root@imran-laptop:~/Desktop# iwlist scan
lo Interface doesn't support scanning.
eth0 Interface doesn't support scanning.
wlan0 Scan completed :
Cell 01 - Address: 00:1B:11:5A:BC:48
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=43/70 Signal level=-67 dBm
Encryption key:on
ESSID:"pingcom"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s
Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000008f601582180
Extra: Last beacon: 2732ms ago
IE: Unknown: 000770696E67636F6D
IE: Unknown: 010482848B96
IE: Unknown: 030101
IE: Unknown: 2A0100
IE: Unknown: 32088C129824B048606C
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
IE: Unknown: DD1E00904C334E101FFFFF000000000000000000000000000000000000000000
IE: Unknown: DD1A00904C340105070000000F000000000000000000000000000000
IE: Unknown: 2D1A4E101FFFFF000000000000000000000000000004000000000000
IE: Unknown: 3D160105030000000F000000000000000000000000000000
Cell 02 - Address: 00:19:5B:47:45:E5
Channel:2
Frequency:2.417 GHz (Channel 2)
Quality=57/70 Signal level=-53 dBm
Encryption key:on
ESSID:"Owera-Guest"
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
Bit Rates:9 Mb/s; 18 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000000079c93363a
Extra: Last beacon: 2776ms ago
IE: Unknown: 000B4F776572612D4775657374
IE: Unknown: 010882848B960C183048
IE: Unknown: 030102
IE: Unknown: 2A0100
IE: Unknown: 32041224606C
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
IE: Unknown: DD0900037F01010006FF7F
IE: Unknown: DD0C00037F020101000002A34000

.
.
.


Step3: Change permission of script to execute , Script is at the bottom.
root@imran-laptop:~/Desktop# chmod -R +x wiscan.pl

Step 4: Run the Script
root@imran-laptop:~/Desktop# ./wiscan.pl
+ --- + ------------------------------ + ------- + -------- + --- + ------ + --------- + ---------------------- + ----------------- +
| # | Name | Quality | Sig Lvl | Enc | Enc T. | Auth T. | Channel | AP MAC |
+ --- + ------------------------------ + ------- + -------- + --- + ------ + --------- + ---------------------- + ----------------- +
| 1 | "pingcom" | 55/70 | -55 dBm | on | WPA v1 | PSK | 2.412 GHz (Channel 1) | 00:1B:11:5A:BC:48 |
| 2 | "Owera-Guest" | 57/70 | -53 dBm | on | WPA v1 | PSK | 2.417 GHz (Channel 2) | 00:19:5B:47:45:E5 |
| 3 | "Difi-Gjestenett" | 50/70 | -60 dBm | off | WEP | N/A | 2.412 GHz (Channel 1) | 00:13:F7:CA:25:D9 |
| 4 | "DVG-5802S" | 53/70 | -57 dBm | on | WPA v1 | PSK | 2.427 GHz (Channel 4) | 06:21:94:00:54:D4 |
| 5 | "Difi-Gjestenett" | 38/70 | -72 dBm | off | WEP | N/A | 2.437 GHz (Channel 6) | 00:13:F7:CA:25:D4 |
| 6 | "ft-test" | 53/70 | -57 dBm | on | WPA v1 | PSK | 2.447 GHz (Channel 8) | 0E:21:94:00:54:D4 |
| 7 | "Einar Aaland's Network" | 44/70 | -66 dBm | on | WPA v1 | PSK | 2.457 GHz (Channel 10) | 00:1F:5B:88:54:13 |
| 8 | "ap2" | 43/70 | -67 dBm | on | WEP | N/A | 2.422 GHz (Channel 3) | 00:19:5B:47:65:F3 |
| 9 | "pingcom" | 43/70 | -67 dBm | on | WPA v1 | PSK | 2.432 GHz (Channel 5) | 00:1B:11:5C:82:01 |
| 10 | "Difi_Adm" | 31/70 | -79 dBm | on | WPA v1 | 802.1x | 5.54 GHz (Channel 108) | 00:24:C4:F9:16:3F |
| 11 | "Difi_Adm" | 32/70 | -78 dBm | on | WPA v1 | 802.1x | 2.437 GHz (Channel 6) | 00:24:C4:F9:16:30 |
+ --- + ------------------------------ + ------- + -------- + --- + ------ + --------- + ---------------------- + ----------------- +


Her is the script, this is written by Timothy Mills, downloaded from Internet, thanks to Timothy Mills, we just did some changes to have MAC addresses or APs. You can copy this and save it as 'wiscan.pl' and change permission to execute..
#!/usr/bin/perl
#############################################################################
# Author: Timothy Mills
# Date : 8 - 4 - 08
# File : wiscan.pl
#
# wiscan.pl takes the output of 'iwlist scan' and makes it in an easier
# to read format for those of us who still deal with the terminal :)
#############################################################################


helpCheck();

#Run the command and suppress error output
$iwlistOut = `iwlist scan 2> /dev/null`;

@myLines = split("\n", $iwlistOut);
@cellArr = [];

printHeading();
printFin("#", "Name", "Quality","Sig Lvl", "Enc", "Enc T.", "Auth T.", "Channel", "AP MAC");
printHeading();

$currNum = 0;
varInit();

foreach (@myLines)
{
if ($_ =~ "Cell [0-9][0-9]")
{
if ($currNum > 0)
{
printFin($currNum, $name, $quality, $sigLvl, $enc, $encType,
$authType, $chn, $mac);

varInit();
}
$currNum++;
}

$cellArr[$currNum] = $cellArr[$currNum]."$_"."\n";

if ($_ =~ "ESSID")
{
handleName($_);
}
elsif($_ =~ "Frequency")
{
handleChn($_);
}
elsif($_ =~ "Address:")
{
handleMAC($_);
}

elsif($_ =~ "Encryption key")
{
handleKey($_);
}
elsif($_ =~ "Quality=[0-9]+/[0-9]+")
{
handleQuality($_);
}
elsif($_ =~ "IE: WPA .+ [0-9]")
{
handleEncType($_);
}
elsif($_ =~ "Authentication Suites")
{
handleAuthType($_);
}

}


if ($currNum > 0)
{
printFin($currNum, $name, $quality, $sigLvl, $enc, $encType, $authType, $chn, $mac);
printHeading();
}
else
{
print("No scan results :'( \n");
}

if (scalar @ARGV == 1)
{
$myNum = ($ARGV[0] =~ "[0-9]+");

print $cellArr[$ARGV[0]] if($myNum && ($ARGV[0]>0 && $ARGV[0] <= $currNum)); } sub helpCheck () { foreach(@ARGV) { helpMsg() if ($_ =~ "--help"); } if (scalar @ARGV == 1 && !($ARGV[0] =~ "[0-9]+")) { helpMsg(); } elsif (scalar @ARGV > 1)
{
helpMsg();
}
}

sub helpMsg ()
{
printf("Usage: wiscan.pl [network number] \n\n");
printf("wiscan is used to make the output of 'iwlist scan' be more readable"
."\n");

printf("from within a terminal. By using the optional argument you may \n");
printf("get the full output for a network from 'iwlist scan'\n\n");

printf("EXAMPLES: \n");
printf("1: ./wiscan.pl -- Lists all wireless networks within range\n");
printf("2: ./wiscan.pl 2 -- Shows full output for second wireless network entry \n in the output of wiscan.pl\n");


exit(0);
}


sub printFin()
{
printf("| %-3s | %-30s | %-7s | %-8s | %-3s | %-6s | %-9s | %-22s | %-17s |\n", $_[0],
$_[1], $_[2], $_[3], $_[4], $_[5], $_[6], $_[7],$_[8]);
}

sub printHeading()
{
printf("+ %-3s + %-30s + %-7s + %-8s + %-3s + %-6s + %-9s + %-22s + %-17s +",
"---", "------------------------------", "-------", "--------", "---", "------", "---------","----------------------","-----------------");


printf("\n");
}

sub varInit()
{
$name = "";
$quality = "";
$sigLvl = "";
$enc = "";
$chn = "";
$mac = "";
$encType = "WEP";
$authType = "N/A";
}

sub handleEncType ()
{
$encType = "WPA v".($_ =~ ".*[0-9]");
}

sub handleQuality ()
{
$qual = $_[0];

@qualArr = split(" ", $qual);

$quality = (split("=", $qualArr[0]))[1];
$sigLvl = (split("=", $qualArr[2]))[1]." dBm";
}

sub handleChn ()
{
$chn = (split(":", $_[0]))[1];
}

sub handleMAC ()
{
$mac = (split(": ", $_[0]))[1];
}

sub handleKey ()
{
$enc = (split(":", $_[0]))[1];
}

sub handleName ()
{
$name = (split(":", $_[0]))[1];
}

sub handleAuthType ()
{
$authType = (split(" ", $_[0]))[4];
}

No comments: