Help with batch file for NAV sweep
Results 1 to 4 of 4

Thread: Help with batch file for NAV sweep

  1. #1
    Junior Member
    Join Date
    Jan 2004
    Posts
    6

    Help with batch file for NAV sweep

    Ok so I need some batch file help.

    What I need it to do - Report if a host is running the rtvscan process. I need the batch file to use an input file with IPs (the input file is where I have the problem).

    Here is what I have - It will only run on one host at a time
    @echo off
    SET IP=%1

    pslist \\%IP% winlogon | FIND /I "WINLOGON" >NUL
    IF ERRORLEVEL 1 echo "Not Windows Client"
    IF ERRORLEVEL 1 GOTO END
    IF ERRORLEVEL 0 GOTO SCAN

    :SCAN
    pslist \\%IP% rtvscan | FIND /I "Rtvscan" >NUL
    IF ERRORLEVEL 1 echo "Nav not running on %IP%"
    IF ERRORLEVEL 1 GOTO END
    IF ERRORLEVEL 0 echo "NAV running on %IP%"

    :END

    Please, I don't mean to be rude, but if you have to ask me what a part of my batch file does, then please don't reply. In short, I need to turn my batch file that runs against one IP at a time to a batch file that runs against an input file, i.e .txt.
    Its good to be at the top of the network food chain.

  2. #2
    Senior Member
    Join Date
    Oct 2001
    Posts
    786
    I'm unsure of how to read input from a text file in a batch program, but it seems that since your batch file works for one host at a time, you could write a C/C++ program that calls your batch file and passes the correct IP from the text-file as an argument to the batch file by concatrating/combining strings of the command (name of batch file) with the argument (IP read from file) and calls that with the "system()" command. I think you need to include windows.h or something for that to work. So basically the C/C++ program would do the task of calling it repeatedly for each IP in your text file.


    I took the time to code it out since you appear to have a non-malicious need for code, since it seems pretty obvious that you need admin privilages to carry out what you are doing anyways. Please note that you will need to recompile it to call your batch file, as my example uses the ECHO command. Simply replace line 9's echo ( char batchprogram[16] = "echo "; ) with the name of your batch file and it should work fine. And it does need to be called from the command line since for some reason it doesn't quite work as expected when double-clicked through the GUI goodness of Windows. I hope that you can use this. And if there are any weird bugs in the code...hopefully you can find them and fix them yourself

    BTW, it is attached, I just quoted it here just in case...

    PHP Code:
    #include <iostream>
    #include <stdlib.h>

    using namespace std;

    int main(int argcchar *argv[])
    {
      
    char commandbuffer[64];
      
    char batchprogram[16] = "echo ";
      
    char filename[16];
      
    char currentip[16];
      
    int  ipcount 0;
      
    FILE *iplist;
      
      
    // Check for the filename argument...
      
    if (argc &gt1)
      {
        
    strcpy(filenameargv[1]);
        
        if ((
    iplist fopen(filename"r")) == NULL)
        {
          
    printf("The file %s could not be opened!"filename);
          
    system("PAUSE");
          return(
    2);
        }
        else
        {
          
    printf("Successfully opened %s!\n"filename);
        }
      }
      else
      {
        
    printf("An argument was not provided.\n\nUsage: %s FILENAME\n\n"argv[0]);
        
    system("PAUSE");
        return(
    1);
      }
      
      
    // Now we should have what we want
      
    printf("Performing quick file check...");
      
      while ( !
    feof(iplist) )
      {
        
    fgets(currentip16iplist);
        
    printf(".");
        
    ipcount++;
      }
      
      
    printf("\n\nWill scan %i PCs - Starting now...\n\n"ipcount);
      
    rewind(iplist);
      
      while ( !
    feof(iplist) )
      {
        
    ipcount--;
        
    fgets(currentip16iplist);
        
        
    printf("%i left to check -\t"ipcount);
        
        
    strcpy(commandbuffer"\0");
        
    strcat(commandbufferbatchprogram);
        
    strcat(commandbuffercurrentip);
        
    system(commandbuffer);
      }
      
      
    fclose(iplist);
      
      
    system("PAUSE");    
      return 
    0;


  3. #3
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    This should work in W2K/XP (you didn't tell us what OS you're using).

    At command prompt:
    C:\> for /f "usebackq" %i in (`type ip_list.txt`) do @your_batch_file %i

    In another batch file:
    for /f "usebackq" %%i in (`type ip_list.txt`) do @your_batch_file %%i
    ( just replace %i with %%i )

    ip_list.txt contains list of IP addressess, one IP per line.

    For more info:
    C:\> for /?

    I didn't know that sysinternal's pslist can take process id or name as argument, cool... I think I can modify your batch file a bit and make a good use of it.

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


  4. #4
    Junior Member
    Join Date
    Jan 2004
    Posts
    6
    In case anyone wanted to see the finished batch file here it is. It can be modified to search for any running process or application.

    Two batch files:
    Syntax - c:\navsweep [input file name.txt]

    navsweep.bat
    @ECHO OFF
    ECHO %TIME% %DATE%
    ECHO ------- %TIME% %DATE% ------- >> NAV_SWEEP.LOG
    ECHO ------- %TIME% %DATE% ------- >> NOT_RUNNING_RTVSCAN.LOG
    echo Running NAV sweep plese wait.....

    SET iplist=%1

    for /f "usebackq" %%i in (`type %1`) do @search.bat %%i

    search.bat
    @ECHO off
    SET IP=%1
    echo Checking %IP%
    pslist \\%IP% winlogon | FIND /I "PID" >NUL
    IF ERRORLEVEL 1 echo %IP% - Not Windows Client >> NAV_SWEEP.LOG
    IF ERRORLEVEL 1 GOTO END
    IF ERRORLEVEL 0 GOTO SCAN

    :SCAN
    pslist \\%IP% rtvscan | FIND /I "PID" >NUL
    IF ERRORLEVEL 1 echo %IP% - Nav not running OR Permission Denyed>> NOT_RUNNING_RTVSCAN.LOG
    IF ERRORLEVEL 1 echo %IP% - Nav not running OR Permission Denyed>> NAV_SWEEP.LOG
    IF ERRORLEVEL 1 GOTO END
    IF ERRORLEVEL 0 echo %IP% - NAV running >> NAV_SWEEP.LOG

    :END
    Its good to be at the top of the network food chain.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •