Forum Topic

[HELP] Windows Batch file scripting

  • Hi Windows scripting masters! Magpapatulong lang sana ako. So I have around 200 hostnames na gusto ko malaman yung IP nila via nslookup. I\'m trying to create a batch file that will loop nslookup for all the 200 servers and output on a single file. The output would be like this:

    Server: UnKnown
    Address: 10.230.5.6

    Name: Server1
    Addresses: 10.200.192.1
    10.200.192.2


    I want to output just the Addresses part so I have this script (below) that I\'m working on but it just loops with no result.

    set servlist=lookup.txt
    for /f %%a in (%servlist%) do call :SUB %%a

    set address=
    goto :EOF
    :SUB %%a

    set address=%1
    for /f \"skip=1 tokens=1,2 delims=:\" %%a in (\'nslookup %address% ^|find /i \"Addresses\"\') do echo %%a %%b >> result.txt

    :EOF


    I appreciate if you can help me. :) Thanks in advance!
  • powershell na lang natin yan. ganito yan sa powershell


    $servers = Get-Content c:\\temp\\servers.txt
    foreach($server in $servers)
    {
    nslookup $server >> c:\\temp\\output.txt
    }
  • beayuna019 Send Message View User Items on January 26, 2015 11:59 AM
    Hi Windows scripting masters! Magpapatulong lang sana ako. So I have around 200 hostnames na gusto ko malaman yung IP nila via nslookup. I\'m trying to create a batch file that will loop nslookup for all the 200 servers and output on a single file. The output would be like this:


    Try this, I remove find, and instead added a condition.

    set servlist=lookup.txt
    for /f %%a in (%servlist%) do call :SUB %%a

    set address=
    goto :EOF
    :SUB %%a

    set address=%1
    for /f \"skip=1 tokens=1,2 delims=:\" %%a in (\'nslookup %address%\') do if %%a == Addresses echo %%a %%b >>result.txt

    :EOF


    Sample output:
    Addresses 422.179.6.8

    You can even remove the skip=1.

    -- edited by ram2010 on Jan 27 2015, 08:32 PM