Announcement

Collapse
No announcement yet.

a program to check network connections

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • a program to check network connections

    oops i deleted my message
    just got smarter too

    ok here is somewhat of the origin message posted

    here is a program to help check network connections
    i wanted a program to check connections made from a startup batch file i have inside
    windows 2000 workstations

    sometimes the connections are not made for whatever unknown reason.
    the program compares the results of the command "net use"
    to a file i have on disk.
    i put the connections i want to check inside the file
    here is a sample file
    workst01.lst
    ------------------------------------------------------
    F: \\SERVER\F-DRIVE
    H: \\SALESSERVER\D-DRIVE
    LPT1 \\SERVER\LASERPRINTER
    LPT3 \\PRINTERSERVER\COLORPRINTER
    ------------------------------------------------------
    place a space between the device and the network resource

    the program does not check for dropped connections as i am
    depending on smart reconnections doing that work for me.
    but i believe you could use this to verify connections that are not
    disconnectd
    place the "OK" and a space before your device name like below, this should work
    --------------------------------------------------------
    OK F: \\SERVER\F-DRIVE
    OK H: \\SALESSERVER\D-DRIVE
    OK LPT1 \\SERVER\LASERPRINTER
    OK LPT3 \\PRINTERSERVER\COLORPRINTER
    --------------------------------------------------------
    do not worry about the case, i convert all strings to upper case
    for comparing inside the results i have gotten from the "NET USE" commmand
    and yes, the "NET" command needs to be in your path.

    please edit and make any corrections that need to be make
    and watch the sleep command inside the dos program for excessive
    cpu usage.

    i have not checked exit errlevel in either program, i just hope they will work

    i hope this program solves some grief for others.


    Code:
    REM NETCNTCK.BAS
    REM POWERBASIC SOURCE CODE
    REM VERSION 10-01-2006
    REM COMPILED WITH POWERBASIC 3.5 FOR DOS
    REM $CPU 80386 'program works on any CPU
    $OPTIMIZE SPEED 'make smallest possible executable
    $DEBUG MAP OFF 'turn off map file generation
    $DEBUG PBDEBUG OFF 'don't include pbdebug support in our executable
    $LIB COM OFF 'turn off PowerBASIC's communications library.
    $LIB CGA OFF 'turn off PowerBASIC's CGA graphics library.
    $LIB EGA OFF 'turn off PowerBASIC's EGA graphics library.
    $LIB FULLFLOAT OFF 'turn off PowerBASIC's floating point support.
    $ERROR BOUNDS ON  'turn on bounds checking
    $ERROR NUMERIC OFF 'turn off numeric checking
    $ERROR OVERFLOW OFF 'turn off overflow checking
    $ERROR STACK OFF 'turn off stack checking
    $COM 0 'set communications buffer to nothing
    $STRING 8 'set largest string size at 8k
    $SOUND 1 'smallest music buffer possible
    $DYNAMIC 'all arrays will be dynamic by default
    $OPTION CNTLBREAK OFF 'don't allow Ctrl-Break to exit program
    $COMPILE EXE 'this tells PB to make a standalone EXE
    $EVENT OFF
    
    ON ERROR GOTO 5020
    FILE2$="NETCNTCK.TMP"
    PRINT
    FILE1$ = COMMAND$
    FILE1$=UCASE$(TRIM$(FILE1$))
    IF FILE1$="" THEN
      PRINT "a filename must be given on the command line"
      PRINT "a 10 second delay is being activated before continuing"
      PRINT "   network connections ---CANNOT--- be checked"
      PRINT
      PRINT
      PRINT "errlevel 0=no problem with the program of network connections"
      PRINT "errlevel 1=no file given on the comamd tail"
      PRINT "errlevel 2=file name given not found"
      PRINT "errlevel 3=a network connection was not found"
      PRINT "errlevel 4=file not found error"
      PRINT "errlevel 5=some kind of error occurred in the program"
      PRINT
      PRINT "this program shells to the command prompt and runs the command"
      PRINT "NET USE          > "+FILE2$
      PRINT "make sure the net command is in your path"
      SLEEP 10
      END 1
      END IF
    PRINT "comparing network connections found in the file: "+file1$
    PRINT
    OPEN FILE1$ FOR INPUT AS #1
    CLOSE #1
    SHELL "NET USE               > "+FILE2$
    OPEN FILE2$ FOR INPUT AS #2
    CLOSE #2
    
    JJ%=0
    DIM A(500) AS STRING
    OPEN FILE2$ FOR INPUT AS #2
    WHILE NOT EOF(2)
    B$=""
     LINE INPUT #2,B$
     B$=UCASE$(TRIM$(B$))
     TEMP%=0
     IF LEN(B$)>0 THEN
     TEMP%=INSTR(B$,"\\")
     END IF
    
    
     IF TEMP%>0 THEN
     INCR JJ%
      IF JJ%=501 THEN
       CLOSE #2
       KILL FILE2$
       PRINT "too many lines in "+FILE2$
       TEMP$=INKEY$
       STOP
       END IF
     A$(JJ%)=B$
     END IF
     WEND
     CLOSE #2
     KILL FILE2$
    
    
    TEST%=0
    TOTALCONNECT%=0
    ON ERROR GOTO 5010
    OPEN FILE1$ FOR INPUT AS #1
    ON ERROR GOTO 5020
    WHILE NOT EOF(1)
    B$=""
     LINE INPUT #1,B$
     B$=UCASE$(TRIM$(B$))
     IF LEN(B$)=0 THEN  GOTO 500
     C$=""
     LASTS$=""
     FOR I%=1 TO LEN(B$)
     S$=MID$(B$,I%,1)
     IF S$=" " AND LASTS$<> " " THEN C$=C$+S$
     IF S$<>" "  THEN C$=C$+S$
     LASTS$=S$
     NEXT I%
    
    BADCONNECT%=1
    TEST%=0
     LASTS$=""
     FOR I%=1 TO JJ%
     B$=UCASE$(TRIM$(A$(I%)))
     D$=""
     LASTS$=""
     FOR K%=1 TO LEN(B$)
     S$=MID$(B$,K%,1)
     IF S$=" " AND LASTS$<> " " THEN D$=D$+S$
     IF S$<>" " THEN D$=D$+S$
     LASTS$=S$
     NEXT K%
     TEST%=INSTR(D$,C$)
     IF TEST%>0 THEN  BADCONNECT%=0
     NEXT I%
     IF BADCONNECT%>0 THEN
       TOTALCONNECT%=1
       PRINT "    "+C$
       END IF
     500
     WEND
     CLOSE #1
     IF TOTALCONNECT%>0 THEN
     PRINT
     PRINT "  the network connection(s) above were not made"
     PRINT
     PRINT
     PRINT " !!!!  YOUR COMPUTER MAY NOT BE SETUP PROPERLY  !!!!"
     PRINT " !!!!  YOUR COMPUTER MAY NOT BE SETUP PROPERLY  !!!!"
     PRINT " !!!!  YOUR COMPUTER MAY NOT BE SETUP PROPERLY  !!!!"
     PRINT
     PRINT "  a 120 second delay is being made to read this error"
     PRINT "              or press a key to continue"
     SLEEP 120
     END 3
     END IF
    
     PRINT "    no connection errors found"
     END 0
    
    
    STOP
    5010
    PRINT "The file "+file1$+" does not exist."
    PRINT "The file should contain all network connections"
    PRINT "  that this program checks for are assigned"
    END 2
    5020
    IF ERR=53 THEN
         PRINT "file not found, possibly "+FILE1$
    END 4
    END IF
    PRINT "a error occurred with this program"
    PRINT "error number";ERR
    END 5


    [This message has been edited by paul d purvis (edited October 06, 2006).]
    p purvis

  • #2
    Code:
    $LINK "Pro.Pbl"
    $LINK "Pro1.Pbl"
    $LINK "Pro2.Pbl"
    Do not appear to be needed. (Except to compile)
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      YOUR RIGHT MICHAEL
      good eye and helpful
      even before i noticed and edited it

      here is the pbcc 4.0 version of the program

      Code:
      REM NETCNTCK.BAS
      REM POWERBASIC PBCC 4.0
      REM VERSION 10-01-2006
      #COMPILE EXE
      REM #DIM ALL
      
      FUNCTION PBMAIN () AS LONG
      
      ON ERROR GOTO 5020
      FILE2$="NETCNTCK.TMP"
      PRINT
      FILE1$ = COMMAND$
      FILE1$=UCASE$(TRIM$(FILE1$))
      IF FILE1$="" THEN
        PRINT "a filename must be given on the command line"
        PRINT "   network connections ---CANNOT--- be checked"
        PRINT
        PRINT
        PRINT "errlevel 0=no problem with the program of network connections"
        PRINT "errlevel 1=no file given on the comamd tail"
        PRINT "errlevel 2=file name given not found"
        PRINT "errlevel 3=a network connection was not found"
        PRINT "errlevel 4=file not found error"
        PRINT "errlevel 5=some kind of error occurred in the program"
        PRINT
        PRINT "this program shells to the command prompt and runs the command"
        PRINT "NET USE > "+FILE2$
        PRINT "make sure the net command is in your path"
        PRINT
        PRINT "  a 10 second delay is being made to read this error"
        PRINT "             or press a key to continue"
         FOR x& = 1 TO 10
      SLEEP 1000
      Char$ = INKEY$
      IF Char$ <> "" THEN EXIT FOR
      NEXT x&
        FUNCTION=1&
        EXIT FUNCTION
        END IF
      PRINT "comparing network connections found in the file: "+file1$
      PRINT
      
      OPEN FILE1$ FOR INPUT AS #1
      CLOSE #1
      
      SHELL ENVIRON$("COMSPEC")+" /C NET USE > "+FILE2$
      
      OPEN FILE2$ FOR INPUT AS #2
      CLOSE #2
      
      JJ%=0
      DIM A(500) AS STRING
      OPEN FILE2$ FOR INPUT AS #2
      WHILE NOT EOF(2)
      B$=""
       LINE INPUT #2,B$
       B$=UCASE$(TRIM$(B$))
       TEMP%=0
       IF LEN(B$)>0 THEN
       TEMP%=INSTR(B$,"\\")
       END IF
      
      
       IF TEMP%>0 THEN
       INCR JJ%
        IF JJ%=501 THEN
         CLOSE #2
         KILL FILE2$
         PRINT "too many lines in "+FILE2$
         TEMP$=INKEY$
         FUNCTION=5&
         EXIT FUNCTION
         END IF
       A$(JJ%)=B$
       END IF
       WEND
       CLOSE #2
       KILL FILE2$
      
      
      TEST%=0
      TOTALCONNECT%=0
      ON ERROR GOTO 5010
      OPEN FILE1$ FOR INPUT AS #1
      ON ERROR GOTO 5020
      WHILE NOT EOF(1)
      B$=""
       LINE INPUT #1,B$
       B$=UCASE$(TRIM$(B$))
       IF LEN(B$)=0 THEN  GOTO 500
       C$=""
       LASTS$=""
       FOR I%=1 TO LEN(B$)
       S$=MID$(B$,I%,1)
       IF S$=" " AND LASTS$<> " " THEN C$=C$+S$
       IF S$<>" "  THEN C$=C$+S$
       LASTS$=S$
       NEXT I%
      
      BADCONNECT%=1
      TEST%=0
       LASTS$=""
       FOR I%=1 TO JJ%
       B$=UCASE$(TRIM$(A$(I%)))
       D$=""
       LASTS$=""
       FOR K%=1 TO LEN(B$)
       S$=MID$(B$,K%,1)
       IF S$=" " AND LASTS$<> " " THEN D$=D$+S$
       IF S$<>" " THEN D$=D$+S$
       LASTS$=S$
       NEXT K%
       TEST%=INSTR(D$,C$)
       IF TEST%>0 THEN  BADCONNECT%=0
       NEXT I%
       IF BADCONNECT%>0 THEN
         TOTALCONNECT%=1
         PRINT "    "+C$
         END IF
       500
       WEND
       CLOSE #1
       IF TOTALCONNECT%>0 THEN
       PRINT
       PRINT "  the network connection(s) above were not made"
       PRINT
       PRINT
       PRINT " !!!!  YOUR COMPUTER MAY NOT BE SETUP PROPERLY  !!!!"
       PRINT " !!!!  YOUR COMPUTER MAY NOT BE SETUP PROPERLY  !!!!"
       PRINT " !!!!  YOUR COMPUTER MAY NOT BE SETUP PROPERLY  !!!!"
       PRINT
       PRINT "  a 120 second delay is being made to read this error"
       PRINT "              or press a key to continue"
      FOR x& = 1 TO 120
      SLEEP 1000
      Char$ = INKEY$
      IF Char$ <> "" THEN EXIT FOR
      NEXT x&
       FUNCTION=3&
       EXIT FUNCTION
       END IF
      
       PRINT "    no connection errors found"
       FUNCTION=0&
       EXIT FUNCTION
       
      5010
      PRINT "The file "+file1$+" does not exist."
      PRINT "The file should contain all network connections"
      PRINT "  that this program checks for are assigned"
      FUNCTION=2&
      EXIT FUNCTION
      5020
      IF ERR=53 THEN
           PRINT "file not found, possibly "+FILE1$
      FUNCTION=4&
      EXIT FUNCTION
      END IF
      PRINT "a error occurred with this program"
      PRINT "error number";ERR
      FUNCTION=5&
      EXIT FUNCTION
         
      
      END FUNCTION

      ------------------




      [This message has been edited by paul d purvis (edited October 06, 2006).]
      p purvis

      Comment

      Working...
      X