Solved

Passing parameters

Posted on 2013-05-19
3
440 Views
Last Modified: 2013-05-19
I need a little bit of help there. I will like to call the attached batch file in a VBScript where I will prompt for an IP address and pass on the IP  (%1) to the batch file

@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions

set IP=%1

REM Get Serial
call :DoSnmpGet "%IP%" ".1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.3.0" "Serial"
REM If no serial found, try the XEROX MIB to see if it responds
if "!Serial!"=="N/A" (
  call :DoSnmpGet "%IP%" ".1.3.6.1.2.1.43.5.1.1.17.1" "Serial"
  REM If no serial found, try the RICOH MIB to see if it responds
  if "!Serial!"=="N/A" (
    call :DoSnmpGet "%IP%" ".1.3.6.1.4.1.367.3.2.1.2.1.4.0" "Serial"
    if NOT "!Serial!"=="N/A" (
      for /F "tokens=1 delims=," %%z in (!Serial!) do set Serial=%%z
      set Serial=!Serial:"=!
    )
  ) else (
    for /F "tokens=1 delims=," %%z in (!Serial!) do set Serial=%%z
    set Serial=!Serial:"=!
  )
)

echo Serial=%Serial%
pause

exit /b

:DoSnmpGet
  REM Use SNMPGET to fetch value for IP and MIB passed in, return in variable passed in
  set %~3=N/A
  for /F "tokens=1-3*" %%t in ('snmpget -O T -v 1 -c public %~1 %~2 2^>nul^|find "="') do (
    set SnmpgetResult=%%w
    if "%%v"=="Hex-STRING:" (
      set SnmpgetResult=!SnmpgetResult: =!
      for /F "tokens=2 delims=[.]" %%z in ("!SnmpgetResult!") do set SnmpgetResult=%%z
    )
    set %~3=!SnmpgetResult!
  )
  exit /b
0
Comment
Question by:Bianchi928
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
Bill Prew earned 250 total points
Comment Utility
Give this a try.  You may want to add some editing if desired.

Of course, you could do it right in the BAT file to with:

set /P "IP=Please enter IP:"

strIP = Inputbox("IP address (xxx.xxx.xxx.xxx)", "Input Required")
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /C script.bat " & strIP), 1, True

Open in new window

~bp
0
 

Author Closing Comment

by:Bianchi928
Comment Utility
Perfect. Thanks mate

Cheers
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Welcome.

~bp
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now