bloginfo

Log Arp Scan

Sep 3rd, 2017 (edited)
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Source https://www.dsfc.net/infrastructure/reseau/scan-entrees-arp-reseau-local-powershell/
  2. Clear
  3. #fichier de logs
  4. $logfile='d:\arp.log'
  5. $logs=@()
  6. $cmd=@()
  7. #Récupération du contenu du fichier de logs existant
  8. If(Test-Path -Path $logfile)
  9. {
  10.     $logs+=Import-CSV -Path $logfile
  11. }
  12. $date=Get-Date
  13. #Balayage par ping du réseau 192.168.1.0/24
  14. For($i=1;$i -lt 255;$i++)
  15. {
  16.     $ping=ping 192.168.1.$i -n 1 -w 5
  17.     #Récupération de la commande arp -a toutes les 60 secondes
  18.     If($date.AddSeconds(60) -lt (Get-Date))
  19.     {
  20.         $cmd+=arp -a
  21.         $date=Get-Date
  22.     }
  23. }
  24. $cmd+=arp -a
  25. #Elimination des doublons du fait de l'exécution régulière de arp -a
  26. $cmd=$cmd|Sort -Unique
  27. #Récupération des adresses ip et mac
  28. ForEach($row in $cmd)
  29. {
  30.     If($row -match '^ +([0-9\.]+) +([0-9a-f\-]+) +[a-z]+ +$')
  31.     {
  32.         $ip=$Matches[1]
  33.         $mac=$Matches[2]
  34.         $logs+=[PSCustomObject]@{date=$date;ip=$ip;mac=$mac}
  35.     }
  36. }
  37. #Sauvegarde des données de la table arp dans le fichier de logs
  38. $logs| Export-CSV -NoTypeInformation -Path $logfile
  39. #Facultatif : affichage des résultats si vous exécutez le script en mode interactif
  40. $logs|Out-GridView -Title 'Log Arp Scan'
  41. $logs=$null
Add Comment
Please, Sign In to add comment