1

I am having great difficulty with a batch file i am working with. With the update i received below, i use nslookup to return the IP of the address.

Is it possible to extract the IP returned with the nslookup command as a variable, and then edit the last two digits to change it to the number 1.

The end command is to ping the changed variable.

Alex
  • 21
  • 5
  • Do a DNS lookup to convert the hostname to an ip-address first (for which standard functions and tools exist) and then ping that ip-address (if the ping results are really needed) rather than trying to extract the ip-address from the ping output ... And you should probably be using powershell by now... – HBruijn Oct 19 '16 at 08:13
  • Thank you, i am new to creating batch files, the nslookup command returns the IP address, how do isolate it to edit it? – Alex Oct 19 '16 at 10:06

1 Answers1

0

Specific to my code this provided the output required

FOR /F "Skip= 4 tokens=2" %%A IN ('nslookup***')  Do
    Set "ip= %%A"

SET "offsets=0.0.0.-14"

@echo off
for /f "tokens=1-4 delims=. " %%a in ("%ip%") do (
    set octetA=%%a
    set octetB=%%b
    set octetC=%%c
    set octetD=%%d
)
FOR /f "tokens=1-4 delims=." %%a in ("%offsets%") do (
    SET /a octetA+=%%a
    SET /a octetB+=%%b
    SET /a octetC+=%%c
    SET /a octetD+=%%d
)
jftuga
  • 5,731
  • 4
  • 42
  • 51
Alex
  • 21
  • 5