You've enabled Delayed Expansion, but aren't using it where it's needed (would eliminate the Call statements), and using it on one line where it's not needed.
And I don't see why you use a For loop to get the DNS address into a variable. Just set it at the start of the file and you can eliminate that loop. Makes it easier to change the DNS server, as you only have to edit one line instead of two.
This should do what you want. You can mix IP Addresses and Hostnames in the same file.
It will determine the IP address by pinging the hostname.
Give it a whirl.
Code:
@Echo Off
SetLocal EnableDelayedExpansion
Set InputFile=ips.txt
Set OutputFile=PNS-Results.csv
Set _DNSSVR=10.100.65.19
IF NOT Exist "%InputFile%" Echo "%InputFile%" file does not exist. &Goto EndScript
For %%R In ("%InputFile%") Do If %%~zR EQU 0 Echo "%InputFile%" file is empty. &Goto EndScript
If Exist "%OutputFile%" Del /F /Q "%OutputFile%"
Ping %_DNSSVR% -n 2 | Find "TTL" >Nul 2>&1
If ERRORLEVEL 1 (Echo "Unable to reach LONADS04 (%_DNSSVR%). Edit script to use an alternative DNS server" &GOTO EndScript)
Echo Hostname,IP Address,IP-Status,FQDN>>%OutputFile%
For /F %%c In ('TYPE "%InputFile%"') Do (
Echo Processing: %%c
Set _Hostname=Not Applicable
Set _IP=%%c
Set _Status=Offline
:: Check if %%c is an IP Address. If not, set _Hostname=%%c
ECHO.%%c|FindStr /R /B /C:"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" >Nul
If ERRORLEVEL 1 (Set _Hostname=%%c)&(Set _IP=Unknown)
::Ping the hostname/IP, check if online and get IP address if a hostname
For /F "Tokens=1-3 Delims= " %%I In ('Ping "%%c" -n 2 -w 100') Do If /I "%%I %%J"=="Reply from" (Set _IP=%%K)&(Set _Status=Online)
If Not "!_IP!"=="Unknown" (
NSLookup.exe %%c %_DNSSVR% 2>Nul|Find /I "Name:" >Nul
If NOT ERRORLEVEL 1 (
For /F "tokens=1* Skip=2" %%k In ('NSLookup.exe %%c %_DNSSVR% 2^>Nul') Do If [%%k]==[Name:] Set _Name=%%l
Echo !_Hostname!,!_IP!,!_Status!,!_Name!>>"%OutputFile%"
) Else (Echo !_Hostname!,!_IP!,!_Status!,Unable to resolve>>"%OutputFile%")
) Else (Echo !_Hostname!,!_IP!,!_Status!,Unable to resolve>>"%OutputFile%"))
:EndScript
EndLocal
EXIT /B 0
HTH
Jerry