<html>
<head>
<title>Available wireless LANs</title>
<meta HTTP-EQUIV="refresh" content="10">
</head>
<body bgcolor="white">
<h1>Wireless LANs found:</h1>
<?
/* PHP script to report wireless networks from the ath0 network interface
Written by RJ Marquette (webmaster@rjmarq.org). No guarantees, warranties, etc.
I created this very quickly. IF you have some revisions for it, please send them
to me. I'm especially interested in being able to have the output look like
phpMyAdmin's browse table, especially with the cool sorting. On the other hand,
how many times do you have so many networks that you have to sort the list to find
what you need?
Use it if you like it. If it breaks you get to keep the pieces.
*/
/* array to hold the channels & frequencies */
$freqs = array(1 => '2.412', 2 => '2.417', 3 => '2.422', 4 => '2.427', 5 => '2.432', 6 => '2.437',
7 => '2.442', 8 => '2.447', 9 => '2.452', 10 => '2.457', 11 => '2.462', 12 => '2.467',
13 => '2.472', 14 => '2.484');
$raw_output = shell_exec('/usr/sbin/iwlist ath0 scan');
//echo "Raw: <pre>$raw_output</pre><br>\n";
/* Check if device driver is loaded */
if (strpos($raw_output,'No such device'))
{ $fail = 2; }
/* check if output is "No scan results */
elseif (strpos($raw_output,'No scan results'))
{ $fail = 1; }
else
{ $fail = 0; } // tests passed
if ($fail == 0)
{
$data_array = explode("\n",$raw_output);
$i=1; //ignore first line; it just says "Scan completed"
//echo "Data row 1: ".ltrim($data_array[$i])."<br>\n";
while ($i<count($data_array))
{
//echo substr($data_array[$i],20,strpos($data_array[$i],':',20)-20)."<br>\n";
$colon_char = strpos($data_array[$i],':');
switch (substr($data_array[$i],20,strpos($data_array[$i],':',20)-20))
{
case 'Mode':
$wlans[$numcells]['mode'] = substr($data_array[$i],$colon_char+1);
break;
case 'Encryption key':
$wlans[$numcells]['encryptionkey'] = substr($data_array[$i],$colon_char+1);
break;
case 'ESSID':
$wlans[$numcells]['essid'] = str_replace("\"","",substr($data_array[$i],$colon_char+1));
break;
case 'Frequency':
$wlans[$numcells]['frequency'] = substr($data_array[$i],$colon_char+1,5);
break;
case 'Bit Rate':
$wlans[$numcells]['bitrate'] .= " " . str_replace("Mb/s","",substr($data_array[$i],$colon_char+1));
break;
case 'Quality':
$slash_char = strpos($data_array[$i],'/');
$wlans[$numcells]['quality'] = substr($data_array[$i],$colon_char+1,$slash_char-$colon_char-1);
break;
} // end of switch statement
if (strpos($data_array[$i],'Cell')) // new network
{
$numcells++;
$wlans[$numcells]['address'] = substr($data_array[$i],strpos($data_array[$i],":"+1));
}
//echo "Network #".$cell_num. " - " . $wlans[$cell_num]['essid'] .
// " - Address is ".$wlans[$cell_num]['address']. "<br>\n";
//echo "Mode is " .$wlans[$cell_num]['mode'].", Encryption key is ".
// $wlans[$cell_num]['encryptionkey']. "<br>\n";
$i++;
}
// output the data
$i=1;
//array_multisort($wlans['quality'],sort_numeric);
//echo "Found $numcells networks:<br>\n";
echo "<table border=1>\n";
echo "<tr><td>ESSID</td><td>Quality</td><td>Mode</td><td>Channel</td><td>Max Speed (Mb/s)</td></tr>\n";
while ($i<=$numcells)
{
if ($wlans[$i]['quality']>=19)
{ $color="#00dd00"; }
elseif ($wlans[$i]['quality']>=10)
{ $color="yellow"; }
else
{ $color="red"; }
// Set channel
$channel = array_search($wlans[$i]['frequency'],$freqs);
echo "<tr bgcolor=\"$color\"><td>" . $wlans[$i]['essid'] . "</td>\n";
echo " <td align=center>" . $wlans[$i]['quality'] . "</td>\n";
echo " <td>" . $wlans[$i]['mode'] . "</td>\n";
echo " <td align=center>" . $channel . "</td>\n";
echo " <td align=center>" . substr($wlans[$i]['bitrate'],strrpos($wlans[$i]['bitrate'],' ')+1) . "</td></tr>\n";
$i++;
}
echo "</table>\n";
}
else
{
echo "<p>Sorry, nothing found.</p>\n";
if ($fail==2)
{ echo "<p>Please check to ensure the Atheros driver has been loaded into the kernel.</p>\n"; }
elseif ($fail==1)
{ echo "<p>Please check to ensure the wireless antenna switch is on.</p>\n"; }
}
?>
</body>
</html>