Computing.Net > Forums > Disk Operating System > DOS Batch Scripting

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

DOS Batch Scripting

Reply to Message Icon

Name: Switchyard Sullivan
Date: February 28, 2003 at 21:32:31 Pacific
OS: Win XP
CPU/Ram: 256 DDR
Comment:

Hey guys, sorry I'm really new at this. I just had a thought to write a script that seems fairly simple, but it's hard for me.

Basically what I want to do is be able to type a domain name, and have the script immediately ping the domain, and write the domain name and the resolved IP to a text file. If possible on top of that, I want to be able to set variables in the script that have certain IPs translate to certain names, which would also be written to the text file.

So for instance, I open the command utility and type "yahoo.com". Can I get this script to ping yahoo and then create and write a new text file that would basically say, "yahoo.com - 64.58.79.230 - Yahoo Homepage" or something like that. Can you guys help me?



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: February 28, 2003 at 22:37:07 Pacific
Reply:

Yep. The only part I did not understand was:

> If possible on top of that, I want to
> be able to set variables in the script
> that have certain IPs translate to
> certain names, which would also be
> written to the text file.

What do you mean by that? You wanna do the way back, that is, identify DNS's by their IPs?

Well, appart from the task discribed in that part of your post which I didn't understand, the following batch script will do the rest:

@echo off

:: Set file where to store the IPs below
set LOG=C:\LogFile.txt

set DNS=
echo.
echo Type domain names to identify, 'd' for defaults, 'q' when done:
:input
set INPUT=
set /P INPUT=
if "%INPUT%"=="" goto input
if /i "%INPUT%"=="q" (
    echo.
    echo Identifying and logging IPs...
    goto loop
)
set DNS=%DNS% %INPUT%
goto input

:loop
if "%DNS%"=="" goto end
for /F "tokens=1* delims= " %%D in ("%DNS%") do (
    set DNS=%%E
    for /F "tokens=2 delims=[]" %%I in ('ping -n 1 %%D') do (
        echo %%D - %%I>> %LOG%
        goto loop
    )
    echo %%D - unable to determine>> %LOG%
)
goto loop

:end
echo Process completed.

BTW, if it's just to get the IPs based on the DNS's, we probably don't need to use PING. There's probably another command that will just identify, which will be faster than PING, which pings each DNS. However, I don't know which command to use.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

________________________________________________________________________


0

Response Number 2
Name: Switchyard Sullivan
Date: March 1, 2003 at 17:01:36 Pacific
Reply:

Wow, thanks so much. The other part that I was refering to would be for me to give a name to a certain IP within the script, so that when the script is logging the IP, it also gives it the preset name.

For my yahoo example in the last paragraph in my first post, is is possible to put in the script that when a certain IP comes it (64.58.79.230) the script also translates it to a specific name? So it logs the domain name, and the IP, and then if say the IP is 64.58.79.230 then the script will also add a name I specify to go with that IP, like "Yahoo Homepage".

Again, thanks for all your help.


0

Response Number 3
Name: Secret_Doom
Date: March 2, 2003 at 11:49:35 Pacific
Reply:

Hey, the following line:

echo Type domain names to identify, 'd' for defaults, 'q' when done:

should actually be:

echo Type domain names to identify, 'q' when done:

Now, in response to your second post - hmmm I understand it now. You would like to have a list of preset names that would go with certain DNS names and their IP names to the log file, and that list would be on the source of the script.

That can be done, but I thought of something that could be even better to you. That would be to have a prompt like the one on the script (the prompt which I stated to be wrong previously), which will log default IPs if you simply type 'd'. That way, you would have a list on the script with some domain names and their titles (preset names) which would be logged if you just typed 'd' (for Defaults) on the prompt.

What do you think of this incrementation? Or do you rather stick with your first idea?

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 4
Name: Switchyard Sullivan
Date: March 2, 2003 at 19:32:35 Pacific
Reply:

Yeah that's basically the idea. One thing though, the script would most likely need to associate the preset names with IPs only. Basically, the list of domain names is huge, but they all reside on a smaller set number of servers. So the idea is the script will basically be able to tell what domains lie on which servers. So by typing domains, it resolves the IP, and then matches the IP to the preset name in the script and gives me the actual server name.

I like your idea for the defaults. I'm not sure how many of the same domain names I will be repeatedly using, but it would be cool to have it in there just in case. Thanks agian man.


0

Response Number 5
Name: Secret_Doom
Date: March 2, 2003 at 21:34:19 Pacific
Reply:

It's all clear now, Sullivan - so, we'll be using BOTH ideas, correct? Here we go:

@echo off
if "%1"=="GoTo" goto %2
%comspec% /v:on /c %0 GoTo start
goto eof

:: =================================================================
:: Common DNS/IP list - FOLLOW EXACT PREFIX PATTERN:
:: - preset names - n;(ip);(name) - e.g.: n;0.0.0.0;Uknown Page
:: - default dns's - d;(dns) - e.g.: d;1.1.1.1
:: The prefixes should begin at the very line begin.
:: =================================================================
n;66.218.71.198;Yahoo Homepage
n;209.51.137.90;AIDS.com Homepage
d;computing.net
d;yahoo.com
d;google.com
:: =================================================================

:start

:: Set file where to store the IPs below
set LOG=C:\LogFile.txt

echo %0? |FIND /i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
set DNS=
echo.
echo Type domain names to identify, 'd' for defaults, 'q' when done:
:input
set INPUT=
set /P INPUT=
if "%INPUT%"=="" goto input
if /i "%INPUT%"=="q" (
    echo.
    echo Identifying and logging IPs...
    goto loop
)
if /i "%INPUT%"=="d" (
    for /F "tokens=2 delims=;" %%A in ('FINDSTR "^d;" %THIS%') do (
        set DNS=!DNS! %%A
    )
) else (
    set DNS=%DNS% %INPUT%
)
goto input

:loop
if "%DNS%"=="" (echo Process completed.&goto eof)
for /F "tokens=1* delims= " %%D in ("%DNS%") do (
    set DNS=%%E
    for /F "tokens=2 delims=[]" %%I in ('ping -n 1 %%D') do (
        for /F "tokens=3 delims=;" %%N in ('FINDSTR "^n;%%I;" %THIS%') do (
            echo %%D - %%I - %%N>> %LOG%
            goto loop
        )
        echo %%D - %%I>> %LOG%
        goto loop
    )
    echo %%D - unable to determine>> %LOG%
)
goto loop

:eof

Tell me if it worked as intended.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

_______________________________________________________________________________


0

Related Posts

See More



Response Number 6
Name: Switchyard Sullivan
Date: March 3, 2003 at 18:58:19 Pacific
Reply:

Wow, it works great. You're the best man!

I also had another question, and I know it's really superfluous, and more of a curiosity thing, but I was wondering, what would be involved in the possibility of having the script also sort all of the preset names by alphabetical order in the final log? Is that even possible?

Like I said, just a curiousity thing, you've already helped me out tons!


0

Response Number 7
Name: Secret_Doom
Date: March 3, 2003 at 19:44:19 Pacific
Reply:

The easiest way I could think of would be to change the log sintax to;

preset name - domain name - ip

example: (the second example is in those cases where no preset name is given)

Yahoo Homepage - yahoo.com - 1.1.1.1
- computing.net - 2.2.2.2

And then give a final SORT on the logfile. However, that sintax looks bad, doesn't it?

Keep the current log sintax and make the alphabetical sort would be too much for what's worth, I believe. It would involve a lot of work.

I can still make it if you're willing to use that new strange sintax, though...

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 8
Name: Switchyard Sullivan
Date: March 3, 2003 at 21:41:24 Pacific
Reply:

"Keep the current log sintax and make the alphabetical sort would be too much for what's worth, I believe."

That pretty much what I figured. I think it's great as is. Thanks for all your help man. You rule :)


0

Response Number 9
Name: Secret_Doom
Date: March 4, 2003 at 11:29:04 Pacific
Reply:

Glad to help.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon

Command.com v cmd stack limit exceeded: how...



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: DOS Batch Scripting

Dos Batch Script with Type www.computing.net/answers/dos/dos-batch-script-with-type/14148.html

Dos batch scripting www.computing.net/answers/dos/dos-batch-scripting/11369.html

performing a find in a DOS Batch www.computing.net/answers/dos/performing-a-find-in-a-dos-batch/14094.html