16719 shaares
  
#Déclaration d'une whitelist de bornes connues
$whitelist='18:a6:f7:c4:a2:7e','a4:08:f5:4b:ac:5a'
#Le fichier de log
$logfile='d:\ssid.log'
$logs=@()
#Récupération du contenu du fichier existant
If(Test-Path -Path $logfile)
{
    $logs+=Import-CSV -Path $logfile
}
$date=Get-Date
#Scan des SSIDs et des BSSIDs
$cmd=netsh wlan show networks mode=bssid
$n=$cmd.Count
For($i=0;$i -lt $n;$i++)
{
    If($cmd[$i] -Match '^SSID[^:]+:.(.*)$')
    {
        $ssid=$Matches[1]
        $i++
        $bool=$cmd[$i] -Match 'Type[^:]+:.(.+)$'
        $reseau=$Matches[1]
        $i++
        $bool=$cmd[$i] -Match 'Authentification[^:]+:.(.+)$'
        $authent=$Matches[1]
        $i++
        $bool=$cmd[$i] -Match 'Chiffrement[^:]+:.(.+)$'
        $chiffrement=$Matches[1]
        $i++
        While($cmd[$i] -Match 'BSSID[^:]+:.(.+)$')
        {
            $bssid=$Matches[1]
            $i++
            $bool=$cmd[$i] -Match 'Signal[^:]+:.(.+)$'
            $signal=$Matches[1]
            $i++
            $bool=$cmd[$i] -Match 'Type[^:]+:.(.+)$'
            $radio=$Matches[1]
            $i++
            $bool=$cmd[$i] -Match 'Canal[^:]+:.(.+)$'
            $canal=$Matches[1]
            $i=$i+2
            If($bssid -notin $whitelist)
            {
                #Consignation des BSSIDs et des SSIDs
                $logs+=[PSCustomObject]@{date=$date;ssid=$ssid;reseau=$reseau;authentification=$authent;chiffrement=$chiffrement;bssid=$bssid;signal=$signal;radio=$radio;canal=$canal}
            }
        }
    }
}
$cmd=$null
#Sauvegarde dans le fichier de logs
If($logs)
{
    $logs| Export-CSV -NoTypeInformation -Path $logfile
    #Facultatif : affichage des résultats si vous exécutez le script en mode interactif
    $logs|Out-GridView -Title 'Log Scan Wifi'
}
$logs=$null 
                   
