#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Pull variable from text file (NSLOOKUP)


    I have the following code that I am using to do batch NSLOOKUP commands and pipe it out to a CSV file, but I am trying to figure out if I can call some of the lists from a text file or csv file and run them instead of editing the script file each time?

    Sorry if the question seems dumb, because I dont do this coding too often, but from what I remeber from a class way back when I think I can... I just dont know how

    Here is the code:


    @echo off
    if exist list.csv del list.csv

    :: list of name servers
    for %%i in (
    10.0.0.1
    10.0.0.2
    10.0.0.3
    ) do (

    :: list of sites
    for %%j in (
    10.2.33.4
    10.2.33.44
    ) do (

    for /f "tokens=1*" %%k in ('nslookup %%j %%i') do (
    if [%%k]==[Server:] set server=%%l
    if [%%k]==[Address:] set address=%%l
    if [%%k]==[Addresses:] set address=%%l
    if [%%k]==[Name:] set name=%%l)
    call echo %%address%%,"("%%name%% ) >>list.csv
    )
    )


    So you see I am calling a list of name servers (%%i) to resolve a list of IPs (%%j). I would love a way to pull both the list of name servers from an updated external file as well as the list of IPs I am looking for from a similar updated external file.

    If I could figure out a way to NBTSTAT -A it as well to pull the machine name details and include the MAC when possible to verify I would be super happy, but then I can't figure out this part, although I am sure I am overlooking some easy way on how to do it.
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    I think it would probably be easier to code using scripting instead of a batch file, such as vbscript or powershell. Just guessing, I haven't kept up with windows shell programming much lately.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    23
    Rep Power
    0

    like this I think


    Originally Posted by JPLAC
    I have the following code that I am using to do batch NSLOOKUP commands and pipe it out to a CSV file, but I am trying to figure out if I can call some of the lists from a text file or csv file and run them instead of editing the script file each time?

    Sorry if the question seems dumb, because I dont do this coding too often, but from what I remeber from a class way back when I think I can... I just dont know how

    Here is the code:


    @echo off
    if exist list.csv del list.csv

    :: list of name servers
    for %%i in (
    10.0.0.1
    10.0.0.2
    10.0.0.3
    ) do (

    :: list of sites
    for %%j in (
    10.2.33.4
    10.2.33.44
    ) do (

    for /f "tokens=1*" %%k in ('nslookup %%j %%i') do (
    if [%%k]==[Server:] set server=%%l
    if [%%k]==[Address:] set address=%%l
    if [%%k]==[Addresses:] set address=%%l
    if [%%k]==[Name:] set name=%%l)
    call echo %%address%%,"("%%name%% ) >>list.csv
    )
    )


    So you see I am calling a list of name servers (%%i) to resolve a list of IPs (%%j). I would love a way to pull both the list of name servers from an updated external file as well as the list of IPs I am looking for from a similar updated external file.

    If I could figure out a way to NBTSTAT -A it as well to pull the machine name details and include the MAC when possible to verify I would be super happy, but then I can't figure out this part, although I am sure I am overlooking some easy way on how to do it.
    @echo off
    if exist list.csv del list.csv

    :: list of name servers
    for /f %%i in (server_ip.txt)
    do (

    :: list of sites
    for /f %%j in (site_ip.txt)
    do (

    for /f "tokens=1*" %%k in ('nslookup %%j %%i') do (
    if [%%k]==[Server:] set server=%%l
    if [%%k]==[Address:] set address=%%l
    if [%%k]==[Addresses:] set address=%%l
    if [%%k]==[Name:] set name=%%l)
    call echo %%address%%,"("%%name%% ) >>list.csv
    )
    )

    i think thats how you do it - i do not think the %% are need just %

    remember to check back it it does

    Bill stewart - here to listen

IMN logo majestic logo threadwatch logo seochat tools logo