Computing.Net > Forums > Programming > NSLOOKUP in a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

NSLOOKUP in a batch file

Reply to Message Icon

Name: tomchesley
Date: July 18, 2008 at 16:41:33 Pacific
OS: ALL
CPU/Ram: 2GB
Product: Generic
Comment:

I have a bacth file that works for most OS's but doesnt for 98 for NSLOOKUP
Any assistance is appreciated
[code]
cls
@ECHO OFF
echo Revised July 13, 2008
echo This will either modify your hosts for new server additions
echo or remove them when it asks you.
echo.
if Windows_NT == %OS% goto not9x
REM Your OS must be 9x or ME
echo You are running an old OS download and run evohosts9x.bat
pause
goto done

:not9x
REM %SystemRoot% determines if 2000 or XP/Vista
set op_sys=NT
set hosts_dir=%SystemRoot%\system32\drivers\etc
cd %hosts_dir%

:create_old
REM This section removes any evo servers added prior and creates hosts.old
echo Creating hosts.old removing any evo server additions

SETLOCAL
SET replace=
IF exist hosts.old DEL hosts.old
FOR /F "tokens=*" %%i IN (HOSTS) DO (
echo %%i | find /V "4x4evolution.com" >> hosts.old
)
echo hosts.old created
echo.
goto xphosts

:getip
REM This section gets current IP for tonkas.no-ip.org
echo.
echo Getting IP for Tonka's web to add to hosts
echo.
rem SETLOCAL
SET SCRIPTNAME=%~n0
echo You might get a couple errors, something like:
echo *** Can't find server name for address
echo and
echo *** Default servers are not available.
echo That's ok as long as you get New IP is
echo.
set %%I = tonkas.no-ip.org
FOR /F "tokens=3 delims=: " %%I IN ('PING -n 1 tonkas.no-ip.org ^| FIND "Reply from"') DO (
SET IP=%%I
FOR /F "tokens=2 delims=:" %%J IN ('NSLOOKUP %%I ^| FIND "Address: "') DO SET DNS=%%J
)
IF NOT DEFINED IP @ECHO %1 is invalid or NETWORK error occurred. && GOTO :EOF
@ECHO.
IF NOT DEFINED DNS @ECHO %1 - invalid DNS name or DNS error occurred. && GOTO :EOF
call set IP=%%DNS:~2,99%%
echo new IP is %IP%
echo.
rem ECHO%DNS%
pause

:create_new
REM This section creates hosts.new by copying hosts.old to it
REM So we can add the new stuff to ip prior to updating hosts
copy hosts.old hosts.new>nul
rem echo hosts.new created before adding the new hosts
rem echo.
rem pause

:add2hosts
REM This section adds the new innfo to the hosts.new
REM There are actually 5 masters skipped on incase the IP changed
REM Which will cause only the TRI servers to show
REM Then copies then overwrites hosts with this hosts.new
echo %IP% master.4x4evolution.com>>hosts.new
echo %IP% master2.4x4evolution.com>>hosts.new
echo %IP% master3.4x4evolution.com>>hosts.new
echo %IP% master4.4x4evolution.com>>hosts.new
copy hosts.new hosts>nul
del hosts.new
goto :EOF

:xphosts
REM This section asks if you just want to use the hosts.old or not
echo Use the hosts file that has evo server mods? (y/n)
echo Answering n will remove all evo server mods
set choice=
set /p choice=Type y or n for choice.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='n' goto useold
if '%choice%'=='N' goto useold
if '%choice%'=='y' goto getip
if '%choice%'=='Y' goto getip
echo "%choice%" is not valid please try again
echo.
goto xphosts

:useold
copy hosts.old hosts>nul
echo All evo server additions were removed
pause
goto :EOF

:done

[/code]



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 20, 2008 at 03:36:28 Pacific
Reply:

"You are running an old OS download and run evohosts9x.bat"

So where is that?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: tomchesley
Date: July 24, 2008 at 20:21:47 Pacific
Reply:

the evohosts9x.bat only does the
echo %IP% master.4x4evolution.com>>hosts.new
echo %IP% master2.4x4evolution.com>>hosts.new
echo %IP% master3.4x4evolution.com>>hosts.new
echo %IP% master4.4x4evolution.com>>hosts.new

and since I have a dynamic ip i have to edit it each time my ip changes, so was hoping to have it all in 1 batch file


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: NSLOOKUP in a batch file

Using nslookup in a batch file www.computing.net/answers/programming/using-nslookup-in-a-batch-file/18194.html

Extract comp. alias in a batch file www.computing.net/answers/programming/extract-comp-alias-in-a-batch-file/11253.html

Get a Folder size in a batch file www.computing.net/answers/programming/get-a-folder-size-in-a-batch-file/9587.html