How to randomly select a line/ip out of a text file, and set it as a variable.
I mean something like:
set IP=TheLine/IPFromOfTheFile
Try this:
@echo off
setlocal EnableDelayedExpansion
set "file=somefile.txt"
set "lines=0"
for /F "usebackq delims=" %%a in ("%file%") do set /a "lines+=1"
set /a "selected=%random%%%%lines%"
set "lines=0"
for /F "usebackq delims=" %%a in ("%file%") do (
if !lines! equ !selected! set "line=%%a"
set /a "lines+=1"
)
echo %line%
pause