bloginfo

Log Wifi Scan

Sep 1st, 2017 (edited)
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Source : https://www.dsfc.net/infrastructure/reseau/journalisation-scans-wifi-powershell/
  2. #Déclaration d'une whitelist de bornes connues
  3. $whitelist='18:a6:f7:c4:a2:7e','a4:08:f5:4b:ac:5a'
  4. #Le fichier de log
  5. $logfile='d:\ssid.log'
  6. $logs=@()
  7. #Récupération du contenu du fichier existant
  8. If(Test-Path -Path $logfile)
  9. {
  10.     $logs+=Import-CSV -Path $logfile
  11. }
  12. $date=Get-Date
  13. #Scan des SSIDs et des BSSIDs
  14. $cmd=netsh wlan show networks mode=bssid
  15. $n=$cmd.Count
  16. For($i=0;$i -lt $n;$i++)
  17. {
  18.     If($cmd[$i] -Match '^SSID[^:]+:.(.*)$')
  19.     {
  20.         $ssid=$Matches[1]
  21.         $i++
  22.         $bool=$cmd[$i] -Match 'Type[^:]+:.(.+)$'
  23.         $reseau=$Matches[1]
  24.         $i++
  25.         $bool=$cmd[$i] -Match 'Authentification[^:]+:.(.+)$'
  26.         $authent=$Matches[1]
  27.         $i++
  28.         $bool=$cmd[$i] -Match 'Chiffrement[^:]+:.(.+)$'
  29.         $chiffrement=$Matches[1]
  30.         $i++
  31.         While($cmd[$i] -Match 'BSSID[^:]+:.(.+)$')
  32.         {
  33.             $bssid=$Matches[1]
  34.             $i++
  35.             $bool=$cmd[$i] -Match 'Signal[^:]+:.(.+)$'
  36.             $signal=$Matches[1]
  37.             $i++
  38.             $bool=$cmd[$i] -Match 'Type[^:]+:.(.+)$'
  39.             $radio=$Matches[1]
  40.             $i++
  41.             $bool=$cmd[$i] -Match 'Canal[^:]+:.(.+)$'
  42.             $canal=$Matches[1]
  43.             $i=$i+2
  44.             If($bssid -notin $whitelist)
  45.             {
  46.                 #Consignation des BSSIDs et des SSIDs
  47.                 $logs+=[PSCustomObject]@{date=$date;ssid=$ssid;reseau=$reseau;authentification=$authent;chiffrement=$chiffrement;bssid=$bssid;signal=$signal;radio=$radio;canal=$canal}
  48.             }
  49.         }
  50.     }
  51. }
  52. $cmd=$null
  53. #Sauvegarde dans le fichier de logs
  54. If($logs)
  55. {
  56.     $logs| Export-CSV -NoTypeInformation -Path $logfile
  57.     #Facultatif : affichage des résultats si vous exécutez le script en mode interactif
  58.     $logs|Out-GridView -Title 'Log Scan Wifi'
  59. }
  60. $logs=$null
Add Comment
Please, Sign In to add comment