|
Answer» I'm trying to write a batch file that gets the IP address of a site using NSLOOKUP, when an IP is found it opens and launches INTERNET explorer using that IP address. Is this possible?
This is my code so far:
@ECHO OFF SET /p var=nslookup nslookup.exe %var%
Not sure how to pass the IP address BACK to the batch file so I can launch internet explorer with the IP address.
thanks use the for loop. for /? for more info or search the forum for examples. the for loop is so important that you can't do things without it.can you post what do you get on cmd screen when you use nslookup ?? Try this:
Code: [Select]@ECHO OFF SET /p var=nslookup nslookup.exe %var% > temp.tmp for /F "tokens=*" %%a in (temp.tmp) do set ipadd=%%a start iexplore.exe %%a del temp.tmp Hope this helps ,Nick(macdad-)
@macdad
this is output from nslookup 74.125.77.103
Code: [Select]DNS request timed out. timeout was 2 seconds. Server: UnKnown Address: 192.168.1.1
Name: ew-in-f103.google.com Address: 74.125.77.103
Code: [Select]@ECHO OFF SET /p var=nslookup: for /f "tokens=1-2*" %%a in ('nslookup %var% ^|findstr "Address:"') do set ip=%%b start iexplore.exe %ip% should work Thanks Dev, haven't worked with Nslookup that much... Thank you Devcom, the code you provided works perfectly.
Question: You have two Address listed. How does the for loop know to start displaying from the 4th line or 2nd address?
Code: [Select]Server: UnKnown Address: 192.168.1.1
Name: ew-in-f103.google.com Address: 74.125.77.103
thank you...Code: [Select]findstr "Address:"search for LINES that contain "Address:"
so output looks like
Address: 192.168.1.1 Address: 74.125.77.103
and then for loop takes second token (%%b) witch are ip's but the ip we wont to get is in last line so firstly for loop set var to 192.168.1.1 and then to 74.125.77.103
thats all
|