-1

I found an IP scanner that I can run in a batch file and it saves the results of the scan into a CSV file. I need help naming that file. My goal is to have the SSID (currently connected to), date, and time all part of the file name. Hyphens/dashes are fine, but I prefer no spaces in the file name.

This is the IP scanner - https://www.nirsoft.net/utils/wireless_network_watcher.html

The command below works for inserting the date (only the date) in the file name and saves results to the same file every time, overwriting previous scan results.

WNetWatcher.exe /scomma "scan-results-%date:~-10,2%%date:~-7,2%%date:~-4,4%.csv"

Are there tags that can be added to insert the time and SSID in to the file name?

Thank you for your help.

silver5
  • 1
  • 2
  • It is your responsibility to search for and utilise code for retrieving the SSID, Date and Time in your required formats. Once you've done so and if you're still having issues, update your post with the new code by editing it accordingly. – Compo Aug 14 '17 at 17:14

2 Answers2

0

A basic framework for how to craft a filename i batch files -- you'll need to do some magic to ensure a good filename results. I'd recommend investigating the text replacement feature of the SET command.

@echo off
set WNW_CURDAT=%DATE%
WNetWatcher.exe /scomma "scan-results-%WNW_CURDAT%.csv"

Good luck, and holler if you get stuck.

0

The SSID can be gathered from netsh.exe and concatenated with the current date from Get-Date in a PowerShell script.

C:>Get-Content .\Get-IPScanLogFilename.ps1
& netsh.exe wlan show interfaces |
    Select-String "\sSSID\s*: (.+)" |
    % { "$($_.Matches.Groups[1].Value)-$(Get-Date -Format FileDateTime).csv" }

A cmd script can then use that script to get a unique file name.

C:>Get-Content .\Get-IPScanLog.bat
@echo off
FOR /F "usebackq tokens=*" %%f IN (`powershell -NoProfile -File Get-IPScanLogFilename.ps1`) DO (SET "LOG_FILENAME=%%~f")
"C:\Program Files (x86)\NirSoft\Wireless Network Watcher\WNetWatcher.exe" /scomma "%LOG_FILENAME%"
lit
  • 14,456
  • 10
  • 65
  • 119